摘要: BFS基础题View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 #define N 201 5 #define INF 0x7fffffff 6 using namespace std; 7 queue<int> Q; 8 int d[N],t[N],n,a,b,cur,next; 9 char inq[N];10 void bfs()11 {12 for(int i=1;i<=n;i++) t[i]=INF;13 memset(inq,0,si 阅读全文
posted @ 2012-05-18 23:08 BeatLJ 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 题目大意:给定n个正整数,问能否分成4组,且每组的和相等。分析:这题就是sticks那题的简化版。思路一样。View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <vector> 5 #define N 20 6 using namespace std; 7 vector<int> edge[4]; 8 int len[N],n,sum; 9 char vis[N],yes;10 int cmp(const void* 阅读全文
posted @ 2012-05-18 20:14 BeatLJ 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 题目数学模型:给定n个正整数,现要将这n个数分成k组,且满足每组的和都相等。求最多能分多少组。这题是经典的剪枝搜索题,原题来自PKU。下面的程序虽然AC了,但是跑不动POJ中discuss中的那组BT数据。View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <vector> 5 #define MAX(a,b) ((a)>(b)?(a):(b)) 6 #define N 64 7 using namespace std; 阅读全文
posted @ 2012-05-18 17:56 BeatLJ 阅读(366) 评论(0) 推荐(0) 编辑
摘要: 跟"非常可乐"那题差不多,只是多了一个打印倒水步骤。View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 #define N 1001 5 #define MIN(a,b) ((a)<(b)?(a):(b)) 6 using namespace std; 7 typedef struct node 8 { 9 int v[2],t,d;10 }node;11 node cur,next;12 queue<node> Q;13 n 阅读全文
posted @ 2012-05-18 12:24 BeatLJ 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 题目大意:英雄打怪,英雄有n个咒语,每个咒语能对怪造成一定的伤害,且只能使用一次,咒语使用的时机不同,伤害不同,具体表现为,当怪的体力小于某个特定值m时,伤害会加倍。每条咒语描述为(a,m),表示怪的体力大于m时伤害为a,其他时间为2*a。问能不能将怪打死,若能输出最少使用的咒语数,否则输出"-1"。当怪的体力小于或等于0时即认为怪死了。分析:要求最少的次数,很容易想到使用BFS,但用DFS的关键在于状态的判重,这题可以将已经使用的咒语列表构成状态,判重时不好处理。若使用迭代加深搜索IDS则不需判重,只是时间可能要多一点。因为n最大不超过10,即最大深度为10,肯定不会超时 阅读全文
posted @ 2012-05-18 11:08 BeatLJ 阅读(410) 评论(0) 推荐(0) 编辑