上一页 1 2 3 4 5 6 7 ··· 12 下一页

2012年8月16日

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 矮人狙击手! 阅读(242) 评论(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) 编辑

2012年8月15日

hdu1372(BFS)

摘要: 简答的BFS求“马”从一点到另一点的最短距离,马走日,BFS即可 1 #include <iostream> 2 #include <stdio.h> 3 #include <cstring> 4 #define Max 0x7f7f7f7f 5 using namespace std; 6 7 int visited[10][10]; 8 int ans[10][10]; 9 char a[5],b[5];10 int dir[9][2]={{-2,1},{-2,-1},{2,1},{2,-1},{-1,2},{-1,-2},{1,2},{1,-2}};1 阅读全文

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

hdu2612(BFS)

摘要: 今天第一次动手写BFS,原理都懂,只是原来一直没有实现过,实现起来感觉还是蛮简单的没有用队列,用的是数组这道题:求2个点到KFC的距离之和,使其最小,可用2次BFS,分别求出2个点到各个KFC的最短距离,然后找出和最小的即可 1 #include <stdio.h> 2 #include <cstring> 3 #define Max 0x7f7f7f7f 4 using namespace std; 5 int visited1[205][205]; 6 int visited2[205][205]; 7 int ans1[205][205]; 8 int ans2[ 阅读全文

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

hdu2680(最短路径问题)

摘要: 这个最短路径问题好,刚开始一直TLE,看了别人的结题报告后,突然感觉是自己笨了,不知道,灵活运用了,这道题用到了一个虚拟节点的问题本题中起始点有多个,如果按照正常的方法来做的话,可能要循环多次,求不同起点的最小值,这样时间就会话费的多些,采用虚拟节点后,把这个点到每个起始点的距离都设置为0,当有某个点到其余的点有相同的最短路径是,任选一条即可,这题就是运用的这点知识,好啊 1 #include<stdio.h> 2 #include<string.h> 3 #define inf 100000000 4 int map[1010][1010]; //注意这道... 阅读全文

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

2012年8月14日

hdu1596(最短路径问题)

摘要: 最短路径的变形,刚开始用g++交,一直超时,后来改用c++交就过了,看来还是c++比较给力#include <stdio.h>#define max(e1,e2) ((e1)>(e2)?(e1):(e2))double safe[1005][1005];int n;int main(){ while(scanf("%d",&n)!=EOF) { //cin>>n; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { //c... 阅读全文

posted @ 2012-08-14 19:42 矮人狙击手! 阅读(875) 评论(2) 推荐(0) 编辑

hdu2544(最短路径问题)

摘要: 跟前面一题一模一样,稍微改了点代码,直接一次AC 1 #include <cstring> 2 #include <stdio.h> 3 #define Max 0x7f7f7f7f 4 using namespace std; 5 int map[205][205]; 6 int dis[205],visited[205]; 7 int n,start,end; 8 void Dijkstra() 9 {10 dis[1]=0;11 int pos;12 for(int i=1;i<=n;i++)13 {14 int min=Max;15 ... 阅读全文

posted @ 2012-08-14 10:53 矮人狙击手! 阅读(235) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 ··· 12 下一页

导航