摘要: 题意:已知起点s,求从s出发,依次到达n个点,然后再回到起点s所需的最短路径。分析:dfs,从第一个点开始,枚举所有的边,遍历到头,当枚举完所有的点。View Code #include <cstdio>#include <cstring>#include <iostream>#include <cmath>#include <cstdlib>using namespace std;int x[500] , y[500];bool vis[500];int n;int GetDis(int a, int b) { return abs 阅读全文
posted @ 2012-07-03 20:56 lenohoo 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 题意:给你n个数,求出所有6个数的组合数分析:dfsView Code #include <cstdio>#include <cstring>#include <iostream>using namespace std;int b[30];int a[10];int n;void Output() { printf("%d",b[a[0]]); for(int i=1;i<6;i++) printf(" %d",b[a[i]]); printf("\n");}void dfs(int dep, 阅读全文
posted @ 2012-07-03 15:08 lenohoo 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 题意: n个人 玩k张牌,你给你上家开始发牌,每发一张,你得把牌首的p张牌放到牌尾去,输出你最终得到的牌的初始位置。分析:模拟View Code #include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn =100100;bool b[maxn];int a[maxn];/ 当前已经发到第i张牌,返回下一张牌的编号int GetNextNumber(int i , int p ,int k) 阅读全文
posted @ 2012-07-03 14:18 lenohoo 阅读(539) 评论(0) 推荐(0) 编辑
摘要: 题意:从点(0,0)出发,目的地为(x,y),其中有一些点不能通过,求最短距离。分析:bfs View Code #include <cstdio>#include <cstring>#include <iostream>#include <queue>using namespace std;const int maxn = 1010;bool vis[maxn][maxn];int dir[4][2] = { {0,-1},{0,1},{-1,0},{1,0} };struct Node { int x,y,step; };int X ,Y , 阅读全文
posted @ 2012-07-03 02:18 lenohoo 阅读(234) 评论(0) 推荐(0) 编辑
摘要: 题意:求最大环的边数,给出一个无向图,图中每条边的长度都是1,求图中最长环的长度是多少。分析:dfs , 开一个数组pan作访问标记View Code #include <cstdio>#include <cstring>#include <iostream>using namespace std;const int maxn = 5000 , maxm = 500050;int pan[maxn];bool vis[maxn];struct Edge{ int v , next; }edge[maxm];int E , head[maxn];int n , 阅读全文
posted @ 2012-07-03 01:44 lenohoo 阅读(188) 评论(0) 推荐(0) 编辑