poj 2762【Going from u to v or from v to u?】
摘要:先用Tarjan求出强连通分量,其他算法也可以的,再缩点,然后从入度为0的点开始暴搜,如果深度达到强连通分量的个数即可行。这一题一定要注意一点:我用cin的时候TLE,该scanf就好了。。。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <vector> 4 using namespace std; 5 6 const int maxN = 1000 + 10; 7 vector<int> edge[maxN]; 8 int low[maxN]; 9 int stack
阅读全文
posted @
2012-09-09 21:05
Shirlies
阅读(166)
推荐(0) 编辑
hdu 1078【FatMouse and Cheese】
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1078人家说是简单题,我说是神题,这个就是大大滴差距\可怜神奇的DP+记忆化搜索只要将各个方向递归退栈后得到的最大值用dp[x][y](这里的最优就是各个方向上的最大值加上此处的cheese)记录下来,以后如果再次搜索到这个地方时可以直接返回该处的值……ps一句:看了别人的题解后才弄出来的……代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 int dp[105][105]; 5 int inp[105][105]; 6 int n,
阅读全文
posted @
2012-08-15 16:16
Shirlies
阅读(183)
推荐(0) 编辑
hdu 1885【Key Task】
摘要:广搜要记录方格里面不同状态时行走的步数注意当当前行走的步数大于记录的步数时要剪枝(当然,在记录方格不同状态时的值不为-1时)代码如下: 1 #include <iostream> 2 #include <cstring> 3 #include <queue> 4 using namespace std; 5 6 struct node 7 { 8 int x,y; 9 int step; 10 int state; 11 }; 12 char map[105][105]; 13 int R,C; 14 int sx,sy; 15 int used[1...
阅读全文
posted @
2012-08-05 00:01
Shirlies
阅读(227)
推荐(0) 编辑
hdu 2616【Kill the monster】
摘要:写的程序运行时间不给力~_~……我用二进制表示状态做的……代码中解释……代码如下: 1 #include <iostream> 2 using namespace std; 3 4 struct spell 5 { 6 int ai,mi; 7 }ss[12]; 8 int n,HP; 9 int minn;10 11 void dfs(int x,int hp)12 {13 if(hp <= 0)//当hp值要小于等于0时,查看x中有多少个1,即用了多少个spell14 {15 int res = 0;16 for(int i = 0...
阅读全文
posted @
2012-08-03 16:20
Shirlies
阅读(284)
推荐(0) 编辑
hdu 1026【Ignatius and the Princess I】
摘要:广搜我用path记录路径,初始为-1,并且可以用path标记该点是否走过,如果为-1则表示没有走过,一举两得,然后用print递归输出路径。在记录路径时我是将点的坐标转化为一个数值即X*M+Y,当输出路径的时候可将path里面的值转化为坐标……代码如下: 1 #include <iostream> 2 #include <queue> 3 #include <cstdio> 4 using namespace std; 5 6 const int maxlen = 100 + 10; 7 struct place 8 { 9 int x,y; 10 in..
阅读全文
posted @
2012-07-31 11:03
Shirlies
阅读(261)
推荐(0) 编辑
hdu 3500
摘要:题意:就是用一个球a去撞另外一个球b(如果两个相邻是撞不了的),球a停在球b前,球b被撞出去了,少了一个球咯,如果一行有多个球,那么就一个传一个咯,题目要求的结果是最后只剩下一个球。每次都得从头开始搜,我认为是不能只用结构体存储'O'的位置的,必须得用数组存储,因为,每次撞球后位置改变了,结构体存储的点的顺序是会变化的,而下一次搜索又是必须得按顺序开始搜的(即从左上角开始),如果对变化后的结构体排序的话,那么回溯回来又怎么办?反正我是想不到办法了,然后改成数组存储了。我写的挺复杂的,其实思路挺简单的。View Code 1 #include <iostream> 2
阅读全文
posted @
2012-03-04 23:09
Shirlies
阅读(321)
推荐(0) 编辑
hdu 1426
摘要:数独,O(∩_∩)O哈哈~做了这道,以后什么数独就可以直接得出答案了……View Code 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 5 int sudo[9][9]; 6 int flag; 7 8 void dfs(int a,int b); 9 int is_repeat(int i,int j,int k); 10 11 int main() 12 { 13 char a; 14 int cas=0; 15 while(cin>>a) 16 ...
阅读全文
posted @
2012-03-02 19:22
Shirlies
阅读(454)
推荐(0) 编辑
uva 784
摘要:#include <iostream>#include <cstdio>#include <cstring>using namespace std;char maze[31][81];char s[81];int xx,yy;int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};void dfs(int x,int y);int main(){int T;char ch;char a[82];int k=0;scanf("%d",&T);getchar();while(T--){int i=0,j;x
阅读全文
posted @
2012-02-23 21:05
Shirlies
阅读(180)
推荐(0) 编辑
hdu 2531
摘要:起初没有看懂题目,无处下手,就去翻翻别人的代码,才知道题目的意思,汗……简单的一般的广搜的变形,这个解释的比较详细http://blog.csdn.net/swm8023/article/details/6765219虽然知道怎么做了,但是还是犯错误,最后与上面这份代码比较之后才找出错误#include <iostream>#include <cstring>#include <queue>using namespace std;char map[102][102];int vis[102][102];int n,m,time,ans;int fx[21],
阅读全文
posted @
2012-02-22 22:35
Shirlies
阅读(289)
推荐(0) 编辑
hdu 2102
摘要:虽然多了一层,但是还是比较基础的搜索题目,在T时间内,其实只要求出最小时间就可以了,然后比较两者,既然是求最小的时间,那么用广搜就比较好了……#include <iostream>#include <cstring>#include <queue>using namespace std;struct node{int f;int x,y;}n1;char map[2][12][12];int vis[2][12][12];int n,p,t,time;int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};int fp,xp,yp
阅读全文
posted @
2012-02-21 19:13
Shirlies
阅读(456)
推荐(0) 编辑
hdu 1732
摘要:参考http://blog.sina.com.cn/s/blog_622684e80100n3gz.html
阅读全文
posted @
2012-02-21 11:59
Shirlies
阅读(168)
推荐(0) 编辑
hdu 1372
摘要:广搜无语,结构体竟然犯错,害我找问题……#include <iostream>#include <queue>using namespace std;typedef struct{char c1,c2;}node;node n1,n2,at;int dx[8]={-2,-1,1,2,2,1,-1,-2};int dy[8]={1,2,2,1,-1,-2,-2,-1};int main(){node m;int x,y;int vis[10][10];while(cin>>n1.c1>>n1.c2>>n2.c1>>n2.c2
阅读全文
posted @
2012-02-20 21:41
Shirlies
阅读(269)
推荐(0) 编辑
hdu 1548
摘要:才开始搞杭电的搜索的题目(这一题算是第二道),首先看到这题,毫不客气的用了深搜,悲剧咯,栈溢出,网上搜了一看,晕,要广搜,好吧,第一次用stl的队列,写完了,样例过了,但是WA了,无语,真的没有发现什么错误啊,拿别人的代码看看,思路大致差不多啊,怎么啦,改了改又提交还是WA,不明所以,在研究这份代码的时候,忽然发现哪里错了,郁闷,貌似是习惯了c语言,把一切东西都定义在一堆,那个队列也定义在前面了,在进行下次数据测试的时候,那个队列并没有清空!#include <iostream>#include <cstring>#include <queue>using
阅读全文
posted @
2012-02-20 20:11
Shirlies
阅读(885)
推荐(0) 编辑