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啊。。晕,麻烦大牛看看。有个问题,连接一定是从一个管子的右边连到另一个管子的左边吗?# 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; bool used[21]; void dfs(int s,int *min) { if(used[s]) return; else { int i; used[s]=1; if(graph[s].y>*min) *min=graph[s].y; for(i=1;i<=graph[s].c;i++) { if(link[graph[s].next[i]].h>=level) { if(link[graph[s].next[i]].f==s) dfs(link[graph[s].next[i]].t,min); else dfs(link[graph[s].next[i]].f,min); } } } } 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); memset(used,0,sizeof(used)); for(j=1;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); int k; int min=-1; dfs(target,&min); if(min>level||!used[1]) printf("No Solution\n"); else { int total=0; for(j=1;j<=pipe;j++) { if(used[j]) total+=graph[j].h-(level-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