摘要: /*DFSDate: 2012/10/11题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1016思路:从1开始找,在从与1之和为质数的val开始,再从与val为质数的开始,当找到最后一个点时判断一下它和1是否为质数,若是则输出*/#include<iostream>#include<cmath>using namespace std;#define maxn 21bool visited[maxn];int arr[maxn];int n,count = 1;bool isPrime(int x){ for(int i 阅读全文
posted @ 2012-10-11 23:48 sorryhao 阅读(145) 评论(1) 推荐(0)
摘要: 题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=2952/*简单DFSDate: 2012/10/11题意和上题差不多,就是求连通分量的个数*/#include<iostream>using namespace std;#define maxn 101char matrix[maxn][maxn];int n,m,t,ans;bool visited[maxn][maxn];int dir[][2] = {{0,-1},{1,0},{0,1},{-1,0}};bool ok(int i,int j){ return i >= 阅读全文
posted @ 2012-10-11 19:13 sorryhao 阅读(168) 评论(0) 推荐(0)
摘要: 题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1241/*简单DFS题意:就相当于求连通分量的个数*/#include<iostream>#include<algorithm>using namespace std;#define maxn 101char matrix[maxn][maxn];bool visited[maxn][maxn];int dir[][2] = {{0,-1},{1,0},{0,1},{-1,0},{-1,-1},{-1,1},{1,-1},{1,1}};int m,n;bool ok(in 阅读全文
posted @ 2012-10-11 18:36 sorryhao 阅读(191) 评论(0) 推荐(0)
摘要: 题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1175/*BFSDate: 2012/10/11题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1175思路:和逃离迷宫思路差不多,一个方向找到底哎,因为printf("N0\n"),错了n次,改了n久O写成了0*/#include<iostream>#include<queue>using namespace std;#define maxn 1001int dir[][2] = {{0,-1},{1 阅读全文
posted @ 2012-10-11 16:48 sorryhao 阅读(493) 评论(0) 推荐(0)