2012年8月16日

求最大公约数

摘要: 还是自己总结下一些简答的东西吧,留着以后用long long gcd (long long a,long long b){ return b==0?a:gcd(b,a%b);}第一次调用的时候a是大于b的,因为这里会判断b==0?,所以第一步要先判断下 阅读全文

posted @ 2012-08-16 22:46 矮人狙击手! 阅读(184) 评论(0) 推荐(0) 编辑

hdu1278(BFS)

摘要: 关于BFS的题目,可以参考http://blog.csdn.net/cambridgeacm/article/category/1169182,比较多,我只做了一部分就做不下去了这几天一直在写BFS,算是二维,三维,优先,指定转弯次数……烦了,真的烦了,下次换个类型写吧题目要求转弯的次数不能超过k,BFS,从一个方向搜到底 1 #include <iostream> 2 #include <stdio.h> 3 #include <cstring> 4 #include <queue> 5 using namespace std; 6 7 int 阅读全文

posted @ 2012-08-16 22:17 矮人狙击手! 阅读(239) 评论(0) 推荐(0) 编辑

poj2251(BFS)

摘要: 三位的bfs,跟二维的差不多 1 #include <iostream> 2 #include <stdio.h> 3 #include <cstring> 4 using namespace std; 5 6 char map[35][35][35]; 7 int ans[35][35][35]; 8 int visited[35][35][35]; 9 int x1,y1,z1; 10 int x2,y2,z2; 11 int l,r,c; 12 int dir[6][3]={{1,0,0},{-1,0,0},{0,-1,0},{0,1,0},{0,0, 阅读全文

posted @ 2012-08-16 18:33 矮人狙击手! 阅读(166) 评论(0) 推荐(0) 编辑

poj3984(BFS)

摘要: 跟前面的几乎是一样的,不过这道题需要记录下路径输出的时候从后往前找,找到第一个时开始输出,所以要用到递归 1 #include <iostream> 2 #include <stdio.h> 3 #include <cstring> 4 #define Max 0x7f7f7f7f 5 using namespace std; 6 7 8 int map[6][6]; 9 int visited[6][6];10 int dir[4][2]={{1,0},{-1,0},{0,-1},{0,1}};11 int ans[6][6];12 int pre[30] 阅读全文

posted @ 2012-08-16 16:36 矮人狙击手! 阅读(725) 评论(0) 推荐(0) 编辑

关于优先队列

摘要: 转自:http://www.cnblogs.com/ffj343967016/archive/2012/07/22/2603632.html 1 #include<iostream> 2 #include<functional> 3 #include<queue> 4 #include<vector> 5 using namespace std; 6 7 8 struct cmp1 9 { 10 bool operator () (int &a, int &b) 11 { 12 return a > b ; // ... 阅读全文

posted @ 2012-08-16 15:49 矮人狙击手! 阅读(189) 评论(0) 推荐(0) 编辑

hdu12429(BFS+优先队列)

摘要: 1 #include <iostream> 2 #include <stdio.h> 3 #include <cstring> 4 #include <queue> 5 #define Max 0x7f7f7f7f 6 using namespace std; 7 struct node 8 { 9 int x; 10 int y; 11 int time ; 12 friend bool operator < ( node a,node b) 13 { 14 return a.time>b.time;//开始错在这个... 阅读全文

posted @ 2012-08-16 15:38 矮人狙击手! 阅读(196) 评论(0) 推荐(0) 编辑

导航