04 2013 档案

摘要:两个关系好的牛之间不能超过一定的距离,两个关系不好的牛之间的距离不能少一定的距离。如果存在负还输出-1,牛1和牛N不连通 输出-2,否则输出他们的之间距离。 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 5 struct N 6 { 7 int u,v,w; 8 } edge[20010]; 9 10 int dis[1010];11 int INF = (1<<29);12 13 int bellman_ford(int n,int e)14 {15 int flag; 阅读全文
posted @ 2013-04-24 22:00 好小孩 阅读(138) 评论(0) 推荐(0)
摘要:这个题意 就是利用虫洞时光倒流,题目中给出的虫洞史有向边!SPFA水过~~这个跑了204ms 第一次写 应该是邻接矩阵的缘故……sad 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 5 using namespace std; 6 7 const int INF = (1<<20); 8 9 10 int dis[100000]; 11 12 struct N 13 { 14 int u,v,w; 15 struct N *next; 16 }*head[510]; 17 阅读全文
posted @ 2013-04-24 21:56 好小孩 阅读(144) 评论(0) 推荐(0)
摘要:求任意两点间的最短距离 若不连通 输出-1 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 5 using namespace std; 6 7 const int Max = 100000001; 8 9 struct N 10 { 11 int v,w; 12 N *next; 13 }*head[210]; 14 15 void init(int n) 16 { 17 for(int i = 0;i < n; i++) 18 { 19 hea... 阅读全文
posted @ 2013-04-24 21:53 好小孩 阅读(105) 评论(0) 推荐(0)
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 5 using namespace std; 6 7 const int Max = 100000001; 8 9 struct N 10 { 11 int v,w; 12 N *next; 13 }*head[110]; 14 15 void init(int n) 16 { 17 for(int i = 1;i <= n; i++) 18 { 19 head[i] = (struct N *)m... 阅读全文
posted @ 2013-04-24 21:50 好小孩 阅读(133) 评论(0) 推荐(0)
摘要:拓扑排序模板题,判断 当前点出度与入度。 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 5 struct N 6 { 7 int data; 8 int n; 9 struct N *next;10 }*head[510];11 12 void init(int n)13 {14 for(int i = 1;i <= n; i++)15 {16 head[i] = (struct N *)malloc(sizeof(struct N));17 h... 阅读全文
posted @ 2013-04-19 21:08 好小孩 阅读(114) 评论(0) 推荐(0)
摘要:大体思路就是简单的拓扑排序。写的时候没有看模板,都是自己一点一点改的,应该没有模板效率高。还用了一点优先队列的思想,用了并查集的方法检查是否存在环。 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 5 using namespace std; 6 7 struct N 8 { 9 int data; 10 int n,money; 11 N *next; 12 }*head[10010]; 13 14 void init(int n)//初始化函数 15 { 16 ... 阅读全文
posted @ 2013-04-19 21:05 好小孩 阅读(156) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 char a[6][6]; 5 int v[6][6],hash[6][6];//V标记是否已经放过,hash标记是否此位置是否进入过队列 6 int n,sum,max; 7 8 struct N 9 {10 int x,y;11 };12 13 14 int judge(int x,int y)15 {16 int i,j;17 for(i = x+1; i <= n; i++)18 if(v[i][y]) return 0;19 else... 阅读全文
posted @ 2013-04-11 08:55 好小孩 阅读(155) 评论(0) 推荐(0)