随笔分类 -  图论

上一页 1 2 3

poj 3328
摘要:#include<iostream>#include<fstream>#include<queue>using namespace std;int n,m;int map[61][31];int sx[61],sy[31];int end[61][31];int top;int d[2][61][31];struct node{ int s,t; int kind; int weight; friend bool operator <(node a,node b){ return a.weight>b.weight; }};int v[2][61 阅读全文

posted @ 2011-05-29 10:35 宇宙吾心 阅读(189) 评论(0) 推荐(0)

poj 1135
摘要:代码:#include<iostream>#include<fstream>#include<queue>using namespace std;struct e{ int data; int cost; e *next;};e edge[501];int n,m;void add(int s,int t,int w){ e *p=new e; p->data=s; p->cost=w; p->next=edge[t].next; edge[t].next=p; e *q=new e; q->data=t; q->cost=w; 阅读全文

posted @ 2011-05-28 10:51 宇宙吾心 阅读(321) 评论(0) 推荐(0)

poj 3653
摘要:代码:#include<iostream>#include<fstream>#include<queue>using namespace std;int n,m;int total;struct e{ int data; int cost; e *next;};e edge[500];struct node{ int data; int w; friend bool operator <(node a,node b){ return a.w>b.w; }};int d[500],v[500];void solve(){ int i,j,k; me 阅读全文

posted @ 2011-05-28 10:10 宇宙吾心 阅读(281) 评论(0) 推荐(0)

poj 3662
摘要:代码:#include<iostream>#include<fstream>#include<queue>using namespace std;int n,m,l;struct e{ int data; int cost; e *next;};e edge[1001];void add(int s,int t ,int w){ e *p=new e; p->data=s; p->cost=w; p->next=edge[t].next; edge[t].next=p; e *q=new e; q->data=t; q->cos 阅读全文

posted @ 2011-05-28 10:09 宇宙吾心 阅读(240) 评论(0) 推荐(0)

poj 3686
摘要:代码:#include<iostream>#include<fstream>using namespace std;int n,m;int link[2501],x[51],y[2501],lx[51],ly[2501];int map[51][51];int w[51][2501];int dfs(int s){ x[s]=1; for(int i=1;i<=m;i++) if(y[i]==0&&lx[s]+ly[i]==w[s][i]) { y[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=s; r 阅读全文

posted @ 2011-05-28 10:06 宇宙吾心 阅读(268) 评论(0) 推荐(0)

poj 1523
摘要:代码:#include<iostream>#include<fstream>using namespace std;struct e{ int data; e *next;};e edge[1001];void add(int i,int j){ e *p=new e; p->data=j; p->next=edge[i].next; edge[i].next=p; e *q=new e; q->data=i; q->next=edge[j].next; edge[j].next=q;}int dfn[1001],v[1001],low[1001 阅读全文

posted @ 2011-05-28 10:05 宇宙吾心 阅读(231) 评论(0) 推荐(0)

poj 1275
摘要:代码:#include<iostream>#include<fstream>#include<queue>using namespace std;struct e{ int data; int cost; e *next;};e edge[25];int n,m;int r[25],num[25];void add(int s,int t,int w){ e *p=new e; p->data=t; p->cost=w; p->next=edge[s].next; edge[s].next=p;}int v[25];int ans;int 阅读全文

posted @ 2011-05-27 10:21 宇宙吾心 阅读(304) 评论(0) 推荐(0)

poj 1523
摘要:代码:#include<iostream>#include<fstream>using namespace std;struct e{ int data; e *next;};e edge[1001];void add(int i,int j){ e *p=new e; p->data=j; p->next=edge[i].next; edge[i].next=p; e *q=new e; q->data=i; q->next=edge[j].next; edge[j].next=q;}int dfn[1001],v[1001],low[1001 阅读全文

posted @ 2011-05-27 09:46 宇宙吾心 阅读(211) 评论(0) 推荐(0)

poj 1144
摘要:割点代码:#include<iostream>#include<fstream>using namespace std;int n;struct e{ int data; e *next;};e edge[101];int v[101],dfn[101],low[101],index;void solve(int s){ int i,j,k; dfn[s]=low[s]=++index; e *p=edge[s].next; v[s]=0; while(p) { if(dfn[p->data]==0) { solve(p->data); if(low[p-& 阅读全文

posted @ 2011-05-26 10:44 宇宙吾心 阅读(397) 评论(0) 推荐(0)

poj 2914
摘要:最小割代码:#include<iostream>#include<fstream>using namespace std;int n,m;int map[501][501];int v[501],com[501],w[501];int cost;int S,T;void search(){ int i,j,k; int maxx; memset(v,0,sizeof(v)); memset(w,0,sizeof(w)); S=T=-1; while(1) { maxx=-1;k=-1; for(i=0;i<n;i++) if(!com[i]&&!v 阅读全文

posted @ 2011-05-26 10:19 宇宙吾心 阅读(411) 评论(0) 推荐(0)

poj 2195
摘要:题意:一个row*col的矩阵,m表示人,H表示房子,.表示空地,人数和房子数相等,如下图:5 5HH..m...............mm..H现在要让所有的人都进入不同的房子内,问总共最少走多少步?代码:#include<iostream>#include<fstream>#include<queue>#include<cmath>using namespace std;int n,m;struct e{ int data; int c,f,w; e *next; e *op;};e edge[400];int x[101],y[101], 阅读全文

posted @ 2011-05-18 17:50 宇宙吾心 阅读(999) 评论(0) 推荐(0)

poj 1087
摘要:题意:有n个不同的插座,有m台不同的机器需要m种插头,有k组转换:插头A能由插头B转换而来。问这些机器最少有几台不能插上插座。代码:#include<iostream>#include<fstream>#include<queue>using namespace std;struct e{ int data; e *next; int c,f; e *op;};e edge[500];int d[500];int start,end;int n,m;int build(){ int i,j,k; queue<int> q; memset(d,0, 阅读全文

posted @ 2011-05-18 16:30 宇宙吾心 阅读(888) 评论(0) 推荐(0)

poj 3352
摘要:题意:一个连通的无向图,求至少需要添加几条边,救能保证删除任意一条边,图仍然是连通的。思路:边的双连通图。其实就是要求至少添加几条边,可以使整个图成为一个边双连通图。用tarjan算法(求割点割边)求出low数组,这里可以简化,然后依据“low相同的点在一个边连通分量中”,缩点之后构造成树(这里可以直接利用low[]数组,low[i]即为第i节点所在的连通分量的标号)。求出树中出度为1的节点数left,答案即为(leaf+1)/2。代码:#include<iostream>#include<fstream>using namespace std;int n,m;stru 阅读全文

posted @ 2011-05-17 19:28 宇宙吾心 阅读(972) 评论(0) 推荐(0)

poj 2117
摘要:题意:一个无向图,现在要去掉其中一个点,要求去掉这个点之后,总连通分支数最大。思路:割点,连通分量。主要分三种情况:1、最普通的情况:如果有边,而且存在割点,就是tarjon算法的深搜过程中求出所有割点的子树的个数(其实也就是如果去掉割点,能使连通分支数增加的个数)的最大值,再加上原来的强连通分支数即可。2、最容易出错的情况:如果没有边,则应该去掉一个点后,连通分支数为原顶点数减去1。3、如果有边,但是图中不存在割点,则输出原来图中连通分支数就行了。代码:#include<iostream>#include<fstream>using namespace std;int 阅读全文

posted @ 2011-05-17 18:54 宇宙吾心 阅读(668) 评论(0) 推荐(0)

poj 2560
摘要:题意:有n个点,并且知道它们的坐标,求连接所有点的最短路径。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;double x[101],y[101];double d[101];double w[101][101];int v[101];int n;void read(){// ifstream cin("in.txt"); int i,j,k; cin>>n; for(i=1;i<=n;i++) cin>>x[ 阅读全文

posted @ 2011-05-17 16:17 宇宙吾心 阅读(413) 评论(0) 推荐(0)

poj 1861
摘要:题意:给出n个点和m条边,求出最小生成树,输出最小生成树权值最大的第一条边,然后再输出最小生成树的边数,以及每一条边代码:#include<iostream>#include<fstream>using namespace std;int n,m;int rank[1001];int f[1001];void init(){ int i; for(i=1;i<=n;i++) { f[i]=i; rank[i]=0; }}int father(int s){ if(s!=f[s]) f[s]=father(f[s]); return f[s];}void union 阅读全文

posted @ 2011-05-17 15:38 宇宙吾心 阅读(476) 评论(0) 推荐(0)

poj 3615
摘要:题意:奶牛们为了比赛要刻苦训练跳木桩。现在有n个木桩,并知道其中m对木桩的高度差。问奶牛们能从木桩u跳到木桩v,最少的跳跃高度是多少?代码:#include<iostream>#include<fstream>using namespace std;int n,m;int map[301][301];int dp[301][301];void read(){// ifstream cin("in.txt"); int i,j,k,s,t; int q; scanf("%d%d%d",&n,&m,&q); m 阅读全文

posted @ 2011-05-17 15:16 宇宙吾心 阅读(378) 评论(0) 推荐(0)

poj 3169
摘要:题意:n头牛编号为1到n,按照编号的顺序排成一列,每两头牛的之间的距离 >=0。这些牛的距离存在着一些约束关系:1.有ml组(u, v, w)的约束关系,表示牛[u]和牛[v]之间的距离必须<= w。2.有md组(u, v, w)的约束关系,表示牛[u]和牛[v]之间的距离必须>=w。问如果这n头无法排成队伍,则输出-1,如果牛[1]和牛[n]的距离可以无限远,则输出-2,否则则输出牛[1]和牛[n]之间的最大距离。代码:#include<iostream>#include<fstream>#include<queue>using name 阅读全文

posted @ 2011-05-17 14:59 宇宙吾心 阅读(341) 评论(0) 推荐(0)

上一页 1 2 3

导航