今天的题有点简单呀。。
250p:
暴搜。。。
450p:
对于边不相交的n个点 (n >= 3)最多有(n-3)*3 + 3条边。
250p:
#include <cstdio> #include <cstring> #include <cctype> #include <cstdlib> #include <cmath> #include <ctime> #include <iostream> #include <map> #include <set> #include <list> #include <sstream> #include <queue> #include <deque> #include <stack> #include <vector> #include <bitset> #include <algorithm> using namespace std; #define clr(a, x) memset(a, x, sizeof(a)) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i,a,b) for(int i=a;i<=b;i++) template <class T> void checkmax(T &t, T x) { if (x > t) t = x; } template <class T> void checkmin(T &t, T x) { if (x < t) t = x; } template <class T> void _checkmax(T &t, T x) { if (t == -1 || x > t) t = x; } template <class T> void _checkmin(T &t, T x) { if (t == -1 || x < t) t = x; } typedef long long ll; class MazeMaker { public: int longestPath(vector <string> maze, int startRow, int startCol, vector <int> moveRow, vector <int> moveCol) ; }; struct Point { int x, y, step; Point() {} Point(int x, int y, int step) : x(x), y(y), step(step) {} }cur; int dx[55], dy[55], n, m, tot; bool vis[55][55]; char s[55][55]; queue <Point> q; int bfs(int x, int y) { q.push(Point(x, y, 0)); memset(vis, 0, sizeof(vis)); vis[x][y] = 1; int ans = 0; while(!q.empty()) { cur = q.front(); q.pop(); x = cur.x, y = cur.y; int step = cur.step; ans = step; for(int i = 0;i < tot; i++) { int xx = x + dx[i]; int yy = y + dy[i]; if(xx < 0 || xx >= n || yy < 0 || yy >= m || vis[xx][yy] || s[xx][yy] == 'X') continue; vis[xx][yy] = 1; q.push(Point(xx, yy, step+1)); } } for(int i = 0;i < n; i++) for(int j = 0;j < m; j++) if(s[i][j] == '.' && !vis[i][j]) return -1; return ans; } int MazeMaker::longestPath(vector <string> maze, int startRow, int startCol, vector <int> moveRow, vector <int> moveCol) { int i, j; n = maze.size(); m = maze[0].size(); for(i = 0;i < n; i++) { for(j = 0;j < m; j++) { s[i][j] = maze[i][j]; } } tot = moveRow.size(); for(i = 0;i < tot; i++) { dx[i] = moveRow[i]; dy[i] = moveCol[i]; } int ans = bfs(startRow, startCol); return ans; } // Powered by FileEdit // Powered by TZTester 1.01 [25-Feb-2003] // Powered by CodeProcessor
#include <cstdio> #include <cstring> #include <cctype> #include <cstdlib> #include <cmath> #include <ctime> #include <iostream> #include <map> #include <set> #include <list> #include <sstream> #include <queue> #include <deque> #include <stack> #include <vector> #include <bitset> #include <algorithm> using namespace std; #define clr(a, x) memset(a, x, sizeof(a)) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i,a,b) for(int i=a;i<=b;i++) template <class T> void checkmax(T &t, T x) { if (x > t) t = x; } template <class T> void checkmin(T &t, T x) { if (x < t) t = x; } template <class T> void _checkmax(T &t, T x) { if (t == -1 || x > t) t = x; } template <class T> void _checkmin(T &t, T x) { if (t == -1 || x < t) t = x; } typedef long long ll; class PlanarGraphShop { public: int bestCount(int N) ; }; #define INF 11111111 bool vis[50005]; void init(int n) { memset(vis, 0, sizeof(vis)); int dep = 1; while(dep*dep*dep <= n) { int limit = (dep - 3)*3 + 3; if(dep == 1) limit = 0; else if(dep == 2) limit = 1; int dep33 = dep*dep*dep ; for(int i = 0;i <= limit; i++) { if(dep33 + i*i > n) break; vis[dep33 + i*i] = 1; } dep++; } } int dp[55555], a[55555]; int solve(int n) { int i, j, tot = 0; for(i = 1;i <= n; i++) if(vis[i]) a[tot++] = i; for(i = 1;i <= n; i++) dp[i] = INF; dp[0] = 0; for(i = 0;i < tot; i++) { for(j = 0;j <= n; j++) if(j + a[i] <= n) { if(dp[j+a[i]] > dp[j] + 1) dp[j+a[i]] = dp[j]+1; } } return dp[n]; } int PlanarGraphShop::bestCount(int n) { init(n); return solve(n); } // Powered by FileEdit // Powered by TZTester 1.01 [25-Feb-2003] // Powered by CodeProcessor