Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
原来那个代码算法错误,但改过后怎么还WA呢。。In Reply To:WA啊。。晕,麻烦大牛看看。有个问题,连接一定是从一个管子的右边连到另一个管子的左边吗? Posted by:yzhw9981 at 2009-04-24 11:35:29 # include <stdio.h> # include <stdbool.h> struct { int lx,rx; int y; int h; int next[100]; int c; }graph[21]; struct { int f; int t; int h; }link[51]; int target,level,pipe,height[21]; int cmp(const void *a,const void *b) { return link[*(int *)b].h-link[*(int *)a].h; } void sort() { int i; for(i=1;i<=pipe;i++) { qsort(graph[i].next+1,graph[i].c,sizeof(int),cmp); } } int dfs(int now,int l) { if(now==1) { if(l>=graph[now].y) { height[1]=l; return 1; } else return -1; } else if(l<graph[now].y) return -1; else { int i; bool flag=0; height[now]=l; for(i=1;i<=graph[now].c&&link[graph[now].next[i]].h>=l;i++) { int pos; if(link[graph[now].next[i]].f==now) pos=link[graph[now].next[i]].t; else pos=link[graph[now].next[i]].f; if(height[pos]>l) { switch(dfs(pos,l)) { case 1: flag=1; break; case -1:return -1;break; }; } } if(flag) return 1; for(;i<=graph[now].c;i++) { int pos; if(link[graph[now].next[i]].f==now) pos=link[graph[now].next[i]].t; else pos=link[graph[now].next[i]].f; if(height[pos]>link[graph[now].next[i]].h) { switch(dfs(pos,link[graph[now].next[i]].h)) { case 1: return 1; break; case -1:return -1;break; }; } } return 0; } } void add(int f,int l) { graph[f].next[++graph[f].c]=l; } int main() { int testcase,i; scanf("%d",&testcase); for(i=1;i<=testcase;i++) { int j,refer[101]; scanf("%d",&pipe); for(j=1;j<=20;j++) height[j]=9999999; for(j=0;j<=100;j++) refer[j]=-1; for(j=1;j<=pipe;j++) { scanf("%d %d %d",&graph[j].lx,&graph[j].y,&graph[j].h); graph[j].c=0; graph[j].rx=graph[j].lx+1; refer[graph[j].lx]=j; } int linknum; scanf("%d",&linknum); for(j=1;j<=linknum;j++) { int t1,t2,t3; scanf("%d %d %d",&t1,&t2,&t3); link[j].h=t2; link[j].f=refer[t1-1]; link[j].t=refer[t1+t3]; add(link[j].f,j); add(link[j].t,j); } scanf("%d %d",&target,&level); sort(); if(dfs(target,level)!=1) printf("No Solution\n"); else { int total=0; for(j=1;j<=pipe;j++) { if(height[j]<9999999) total+=graph[j].h-(height[j]-graph[j].y); } printf("%d\n",total); } } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator