搜索
smallacmer
这个作者很懒,什么都没留下…
展开
-
DFS Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 26365 Accepted Submission(s): 7218P原创 2011-09-12 15:29:14 · 402 阅读 · 0 评论 -
http://acm.uestc.edu.cn/problem.php?pid=1480&cid=164
#include#include#include#define N 255using namespace std;int map[N][N];int dx[]={1,0,0,-1};int dy[]={0,1,-1,0};struct str{ int x; int y; int step; bool operator<(const str& cur) const {r原创 2012-05-15 13:32:20 · 1237 阅读 · 0 评论 -
http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1186
问题描述It's an easy problem. I will give you a binary tree. You just need to tell me the width of the binary tree.The width of a binary tree means the maximum number of nodes in a same level.原创 2012-07-07 15:31:30 · 559 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=99&&单词拼接
描述 给你一些单词,请你判断能否把它们首尾串起来串成一串。前一个单词的结尾应该与下一个单词的道字母相同。如alohadogarachnidgophertigerrat可以拼接成:aloha.arachnid.dog.gopher.rat.tiger输入 第一行是一个整数N(0每组测试数据的第一行是一个整数M,表示该组测试数据中有M(2原创 2012-07-08 16:53:46 · 613 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=4337&&dfs
一道深搜题,给你一些朋友的关系,让你找到这样的一个排列,相邻的人是朋友,,AC代码:#include#include#include#define N 180using namespace std;bool map[N][N],vis[N];int path[N];bool flag;int n,m,res;void dfs(int x){ if(flag) retu原创 2012-08-03 14:37:12 · 717 阅读 · 0 评论 -
Saving Princess claire_&&http://acm.hdu.edu.cn/showproblem.php?pid=4308
BFS入门题。。AC代码:#include#include#include#include#include#include Q;#define N 5005using namespace std;typedef struct node{ int x; int y; int step; bool flag; bool operator<(const node& a原创 2012-07-20 18:01:15 · 604 阅读 · 0 评论 -
Find The Multiple&&http://poj.org/problem?id=1426
一道关于隐式图的搜索题,bfs和dfs都行,,题意:给你一个数,让你求一个数是该数的倍数,但是要求该数只有0和1构成。需要注意的是要用bfs时需要自己写一下队列。BFS:#include#include#include#includeusing namespace std;typedef long long L;L Queue[20000000];int rear,fro原创 2012-07-24 10:38:55 · 583 阅读 · 0 评论 -
zb的生日&&dfs
#include#include#include#include#define N 25using namespace std;int minx,sum,n;int s[N];bool flag;void dfs(int sum1,int cur){ if(flag||cur==n) return; if(abs(sum-2*sum1)<min原创 2012-07-24 11:19:24 · 568 阅读 · 0 评论 -
Curling 2.0&&http://poj.org/problem?id=3009
DescriptionOn Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a squa原创 2012-07-23 19:19:54 · 989 阅读 · 0 评论 -
棋盘问题&&http://poj.org/problem?id=1321
Description在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n原创 2012-07-23 16:36:59 · 726 阅读 · 0 评论 -
Dungeon Master&&http://poj.org/problem?id=2251
广搜入门题,不过图是三维的~~AC代码:#include#include#include#include#include#define N 35#includeusing namespace std;typedef struct node{ int x; int y; int z; int step; friend bool operator<(node a,n原创 2012-07-24 17:04:27 · 715 阅读 · 0 评论 -
Red and Black&&http://acm.hdu.edu.cn/showproblem.php?pid=1312
DFS不解释。。#include#include#include#include#define N 50using namespace std;int n,m;char map[N][N];int sum;void dfs(int x,int y){ if(map[x+1][y]=='.') {sum++;map[x+1][y]='#';dfs(x原创 2012-07-25 13:17:27 · 1172 阅读 · 0 评论 -
幸运三角形&&http://acm.nyist.net/JudgeOnline/problem.php?pid=491
经典的dfs题,子集的构造方法为难点。。AC代码:#include#include#include#define N 25using namespace std;bool num[N][N];int res[N][N];int n,sum,half;void dfs(int cur){ if(cur==n+1){sum++;return;} fo原创 2012-07-30 09:52:33 · 645 阅读 · 0 评论 -
回溯法之n皇后问题
#include#include#include#define N 20using namespace std;bool vis[3][N];int sum,a[10];int n;void dfs(int cur){ if(cur==n){sum++;return;} for(int i=0;i<n;++i) if(!vis[0][i]&&!vis原创 2012-07-30 18:26:18 · 1222 阅读 · 0 评论 -
八数码问题和bfs中的判重方法
所谓八数码问题就是有一个编号为1~8的正方形滑块被摆成3行3列(留一个格子空着)每次可以把与空格相邻的滑块(有公共边的才算相邻)移动到空格中,而它原来的位置就成为了新的空格,给定初始的局面和目标局面,你的任务就是计算出最少的移动步数,如果无法达到目标局面,就输出-1.AC代码:#include#include#include#include#include#define原创 2012-08-01 17:31:24 · 1555 阅读 · 1 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=488
对于素数环,,可以先打表求出40以内素数,然后dfs,,,,素数环时间限制:1000 ms | 内存限制:65535 KB难度:2描述 有一个整数n,把从1到n的数字无重复的排列成环,且使每相邻两个数(包括首尾)的和都为素数,称为素数环。为了简便起见,我们规定每个素数环都从1开始。例如,下图就是6的一个素数环。输入 有多组测试数据,每组输原创 2012-03-22 14:43:21 · 1345 阅读 · 0 评论 -
蓝桥杯&&奇怪的比赛
某电视台举办了低碳生活大奖赛。题目的计分规则相当奇怪:每位选手需要回答10个问题(其编号为1到10),越后面越有难度。答对的,当前分数翻倍;答错了则扣掉与题号相同的分数(选手必须回答问题,不回答按错误处理)。每位选手都有一个起步的分数为10分。某获胜选手最终得分刚好是100分,如果不让你看比赛过程,你能推断出他(她)哪个题目答对了,哪个题目答错了吗?如果把答对的记为1,答错的记为0原创 2012-04-08 20:09:26 · 1119 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=325
这题其实是0-1背包题,但是用搜索比较好,,dfs就是考虑所有可能情况,从而得出最优解,dfs最重要的是要找到回溯的条件,即递归结束的条件。。#include#include#include#include#includeusing namespace std;int a[21];int sum1,sum2, minx;void dfs(int cur,int n){原创 2012-03-21 10:49:15 · 490 阅读 · 0 评论 -
poj&&1753
http://poj.org/problem?id=1753DescriptionFlip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16原创 2011-10-13 11:40:31 · 498 阅读 · 0 评论 -
Substrings &&http://acm.hdu.edu.cn/showproblem.php?pid=1238
话说这两天心里挺纠结的,,总是静不下心学习,,放假留校的孩纸伤不起啊!!!。。。题意:这是一道搜索入门题,就是找所有字符串共有的最长串的长度。。。先把所有字符串从小到大排序,找出最短串,然后枚举最短串,(和反转串)需要注意一点就是从长到短进行枚举,,,一旦找到就是答案。。。#include#include#includeusing namespace std;string s[1原创 2012-01-06 14:49:37 · 538 阅读 · 0 评论 -
连连看
#include #include #include using namespace std;struct node{ int x, y; int t, d;};queue q;int n, m, map[1002][1002], prove;int visit[1002][1002][4]; //记录第(i,j)个点4个方向是否已走过,0为未走过。int qr原创 2012-01-10 11:51:27 · 598 阅读 · 0 评论 -
B 最大覆盖
这是北邮12月月赛题,,广搜入门。。。。#include#includeusing namespace std;typedef struct {int x,y;}Node;Node p;int dx[4]={0,0,-1,1};int dy[4]={1,-1,0,0};int aa[20][20];char map[20][20];bool visit[20][20];原创 2012-01-05 21:24:31 · 469 阅读 · 0 评论 -
二分查找求函数的区间最小值&&http://acm.hdu.edu.cn/showproblem.php?pid=2899
Strange fuctionTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 792 Accepted Submission(s): 607Problem DescriptionNow, here is a fuction原创 2012-03-27 15:08:39 · 1062 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=2199&&二分查找求高次方程的根
#include#include#include#define exp 1e-7using namespace std;double f(double x){ return 8*pow(x,4.0)+7*pow(x,3.0)+2*pow(x,2.0)+3*x+6;}int main(){ int T; scanf("%d",&T); while(T--) { int原创 2012-03-27 14:50:22 · 1142 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=27
搜索入门题。。。#include#include#includeusing namespace std;int map[105][105];void dfs(int x,int y){ if(!map[x][y]) return; map[x][y]=0; dfs(x-1,y);dfs(x+1,y);dfs(x,y-1);dfs(x,y+1);}int main(){原创 2012-03-29 19:22:33 · 580 阅读 · 0 评论 -
白皮书&&黑白图像
深搜模板题~~~#include#include#include#define N 100using namespace std;int map[N][N];void dfs(int x,int y){ if(!map[x][y]||map[x][y]==-1) return; map[x][y]=-1; dfs(x-1,y+1);dfs(x-1,y);dfs(x-1,原创 2012-03-29 16:53:56 · 553 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=58
bfs搜索水题进行时~~~~#include#include#include#include#includeusing namespace std;int map[9][9]={1,1,1,1,1,1,1,1,1, 1,0,0,1,0,0,1,0,1, 1,0,0,1,1,0,0,0,1, 1,0,1,0,1,1,0,1,1, 1,0,0,0,0,1,0,0,1,原创 2012-03-29 20:39:28 · 933 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=32&&DFS
简单的DFS应用,求排列组合的种类数。。这里需要注意的是下一层都比当前层数小。。。#include#includeusing namespace std;int a[10];bool visit[10];void dfs(int x,int cur,int deep){ if(cur==deep+1) //回溯条件 { for(int i=1;i<=deep;++i)原创 2012-03-21 09:40:59 · 438 阅读 · 0 评论 -
一个数n的全排列&&DFS
#include#includeusing namespace std;int a[10];bool visit[10];void dfs(int cur,int n){ if(cur==n+1) return; //for(int i=n;i>0;--i)从大到小全排列 for(int i=1;i<=n;++i)//从小到大全排列 { if(!visit[i])原创 2012-03-21 10:02:27 · 459 阅读 · 0 评论 -
数独游戏
#include #include#include#include#define N 85#define CLR(arr,val) memset(arr,val,sizeof(arr))using namespace std;void in(int &a){ char ch; while((ch=getchar())'9'); for( a=0;ch>='0原创 2013-06-04 10:22:43 · 2286 阅读 · 1 评论