摘要:
题目链接。分析:应当用字典树,但stl的map做很简单.#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 20;map m;int main() { char s[maxn], s1[maxn], s2[maxn]; while(gets(s), s[0] != 0) { sscanf(s, "%s%s", s1, s2); m[s2] = s1; } while(g... 阅读全文
摘要:
题目链接。题目大意:N个球,从1~N编号,质量不同,范围1~N,无重复。给出小球间的质量关系(#include #include #include #include #include #include #include #include using namespace std;const int maxn = 200+10;bool G[maxn][maxn];int n, m, ind[maxn], a[maxn];bool topsort() { for(int i=n; i>=1; i--) { int k; for(k=n; k>=1; k--) ... 阅读全文
摘要:
题目链接。题目大意:三维迷宫,搜索从s到e的最小步骤数。分析:#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 35;int dx[] = {0, 0, -1, 1, 0, 0};int dy[] = {0, 0, 0, 0, -1, 1};int dz[] = {-1, 1, 0, 0, 0, 0};char G[maxn][maxn][maxn];bool vis[maxn][maxn][maxn];int 阅读全文
摘要:
题目链接。分析:用 dfs 一行一行的搜索,col记录当前列是否已经放置。AC代码如下:#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 10;int n, k, cnt;bool col[maxn];char G[maxn][maxn];void dfs(int row, int num) { if(num == k) { cnt++; return ; } if(row+1 > n) retur... 阅读全文