上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 36 下一页

2011年5月17日

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 宇宙吾心 阅读(376) 评论(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)

poj 2502

摘要: 题意:在一个城市里,分布着若干条地铁线路,每条地铁线路有若干个站点,所有地铁的速度均为40km/h。现在你知道了出发地和终点的坐标,以及这些地铁线路每个站点的坐标,你的步行速度为10km/h,且你到了地铁的任意一个站之后就刚好有地铁出发。问你从出发点到终点最少需要多少时间。思路:dijkstra。构图:把起点,终点,以及每个地铁站作为一个图的所有顶点,所有顶点i和j两两之间,均有边权为w = dis/ 10 (km/h) 的边相连,之外,任意地铁线路的任意两个相邻的站点,均有边权为w = dis/ 40 (km/h)的边相连。然后就是求最短路径了。代码:#include<iostream 阅读全文

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

2011年5月16日

poj 2001

摘要: trie树代码:#include<iostream>#include<fstream>using namespace std;int n;struct e{ int state[26]; int cnt;};e tree[20004];char c[1004][24];int state;void insert(int s){ int i,j=0; for(i=0;i<strlen(c[s]);i++) { if(tree[j].state[c[s][i]-'a']==0) { tree[j].state[c[s][i]-'a']= 阅读全文

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

poj 2528_2

摘要: 代码:#include<iostream>#include<fstream>using namespace std;struct e{ int l,r; bool isa;};e tree[80001];int n;struct f{ int num,s,l;};f b[20001];int c[10001][2];int cmp(const void *a,const void *b){ f *s=(f*)a; f *t=(f*)b; return s->l-t->l;}void build(int s,int t,int p){ tree[p].l=s; 阅读全文

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

poj 1823

摘要: 代码:#include<iostream>#include<fstream>using namespace std;struct e{ int l,r,cnt,cntl,cntr; int state;};e tree[48001];int n,m;void build(int s,int t,int p){ int i,j,k; tree[p].l=s;tree[p].r=t; tree[p].state=-1; tree[p].cnt=tree[p].cntl=tree[p].cntr=t-s+1; if(s==t) return; else { k=(s+t)&g 阅读全文

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

poj 2777

摘要: 代码:#include<iostream>#include<fstream>using namespace std;int n,m,c;struct e{ int l,r; int state; bool id;};e tree[300001];void build(int s,int t,int p){ int i,j,k; tree[p].l=s; tree[p].r=t; if(s==t) return; k=(s+t)>>1; build(s,k,p*2); build(k+1,t,2*p+1);}void update(int s,int t,in 阅读全文

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

poj 3368_2

摘要: 线段树代码:#include<iostream>#include<fstream>using namespace std;int n,m;struct e{ int l,r,max,maxl,maxr;};e tree[300001];int b[100001];void build(int s,int t,int p){ int i,j,k; tree[p].l=s; tree[p].r=t; if(s==t) { tree[p].max=tree[p].maxl=tree[p].maxr=1; return; } k=(s+t)>>1; build(s, 阅读全文

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

2011年5月14日

poj 2255

摘要: 题意:给出一棵二叉树的前序遍历和中序遍历,输出这棵树的后序遍历。代码:#include<iostream>#include<fstream>using namespace std;int n;char c1[30],c2[30];struct e{ char c; e *left,*right;};e * solve(int p,int q,int s){ int i; e *f=new e; for(i=q;i<=s;i++) if(c2[i]==c1[p]) break; f->c=c1[p]; if(i==q) f->left=NULL; els 阅读全文

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

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 36 下一页

导航