02 2013 档案

摘要:http://poj.org/problem?id=3268不知道怎么回事,问题感觉今天读不懂题..题目要求求有向图中,除X外其余所有点到X的最短往返路径中,最长的那一个.FLOYD算法可以很容易的求出有向图中任意两点的最短路径,但是此题用FLOYD会超时.先用一次Dijkstra,求出从X到其余所有点的最短路径(这相当于回来时的长度),然后将这些路径记录,再将邻接矩阵转置,再用一次Dijkstra,将两次路径相加,找出最大的就可以了 1 #include <stdio.h> 2 #include <stdlib.h> 3 #define INF 0x0fffffff 阅读全文
posted @ 2013-02-28 14:24 linyvxiang 阅读(208) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1308并查集。1.不能有环,即只能有一个节点的入度为零 2.除根节点外,其余所有结点的入度必需为1 3.空树也是树 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <set> 5 #include <iterator> 6 using namespace std; 7 int father[10002]; 8 int degree[10002]={0}; 9 set<int 阅读全文
posted @ 2013-02-16 14:22 linyvxiang 阅读(305) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2488DFS+回溯,其实不用从所有节点开始搜索,因为要求输出的是字典序,所以只从A1开始搜索,能一次搜到便是存在,否则不存在。写完代码才意识到。另外注意字典序时,方向数组要写对。 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <stack> 5 using namespace std; 6 int c; 7 int n,p,q; 8 int start_x,start_y; 9 int t 阅读全文
posted @ 2013-02-14 16:04 linyvxiang 阅读(364) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2243BFS模板题 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <queue> 5 using namespace std; 6 char pos_start[3],pos_end[3]; 7 bool visited[20][20]={false}; 8 int dis[20][20]={0}; 9 typedef struct Node {10 int x,y;11 }Node;12 阅读全文
posted @ 2013-02-14 10:15 linyvxiang 阅读(171) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1979DFS模板题. 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 int W,H; 5 char map[22][22]; 6 int count=0; 7 bool check(int x,int y) 8 { 9 if(!(1<=x&&x<=H&&1<=y&&y<=W)) return false;10 return true;11 }12 阅读全文
posted @ 2013-02-14 09:23 linyvxiang 阅读(269) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1562只想问一句,还敢更坑么?每一行数据后都可能有多个空格。。 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 int m,n; 5 char map[102][102]; 6 void find(int *x,int *y) 7 { 8 int i,j; 9 for(i=1;i<=m;i++) 10 for(j=1;j<=n;j++)11 if(map[i][j]=='@') {12 ... 阅读全文
posted @ 2013-02-06 12:22 linyvxiang 阅读(168) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2231水题。 1 #include <stdio.h> 2 #include <algorithm> 3 using namespace std; 4 long long numbers[10002]; 5 int main() 6 { 7 int N; 8 while(scanf("%d",&N)!=EOF) { 9 int i;10 for(i=0;i<N;i++) 11 scanf("%lld",&numbers[i]);12 sort(numbe. 阅读全文
posted @ 2013-02-06 10:03 linyvxiang 阅读(176) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2081打表. 1 #include <stdio.h> 2 int numbers[500001]; 3 bool flags[500001*10]={false}; 4 int main() 5 { 6 int i; 7 numbers[0]=0; 8 flags[0]=true; 9 numbers[1]=1;10 flags[1]=true;11 for(i=2;i<=500000;i++) {12 if(numbers[i-1]-i>0&&(flags[numbers[... 阅读全文
posted @ 2013-02-06 09:48 linyvxiang 阅读(161) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1936简单题,没什么需要特别注意的。 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 char *q,*p,*r; 5 bool check(char ch,char *dst) 6 { 7 while(*dst) { 8 if(*dst==ch) { 9 r=dst+1;10 return true;11 }12 dst++;13 }14 ... 阅读全文
posted @ 2013-02-06 09:24 linyvxiang 阅读(143) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3077念完题目也知道这题需要递归,当为要求的10的整数幂时返回,否则按四舍五入,再将幂加1,继续递归。 1 #include <stdio.h> 2 #include <math.h> 3 #include <stdlib.h> 4 void trans(int *p,int base) 5 { 6 if((*p)<(int)pow(10,base)) return; 7 if((*p)==pow(10,base)) return; 8 if((*p)>pow(10,base)) { 9 .. 阅读全文
posted @ 2013-02-05 16:17 linyvxiang 阅读(166) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2305和2105一样的,练习库函数,注意itoa在g++下面是不存在的。 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <stack> 5 using namespace std; 6 int main() 7 { 8 int b; 9 char p[1020],m[10];10 while(scanf("%d",&b)!=EOF) {11 if(b==0) r 阅读全文
posted @ 2013-02-05 15:55 linyvxiang 阅读(160) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2105看到有人写的博文,才知道的这个库函数,用一下,确实好用~strtol: string to long int 第一个参数为要转换的字符串的指针,第二个一般不用,为出错时返回的二级指针,第三个为字符串中数字的基数,而且对于大小写字母通吃. 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 int main() 5 { 6 char str[10]; 7 int N; 8 while(scanf("%d&quo 阅读全文
posted @ 2013-02-05 15:30 linyvxiang 阅读(178) 评论(0) 推荐(0)