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 |
Re:用网络流吧In Reply To:郁闷,一直都是WA,请牛人帮忙看下呀(code)真不知道怎么办了 Posted by:huicpc21 at 2005-08-18 10:40:11 > 算法思想是这样的,对S个人的要求按最小的size进行排序,然后顺序扫描求解 > #include<ctype.h> > #include<stdio.h> > struct node > { > int x; > int y; > }; > > main() > { > char ch[30],c[21][2]; > int m,min,t,flag,sum,a[6],s,i,j; > struct node no[30]; > long k; > for (k=0;;k++) > { > scanf("%s",ch); > if (!strcmp(ch,"ENDOFINPUT")) > break; > sum=0; > scanf("%d",&s); > for (i=1;i<=s;i++) > scanf("%s",c[i]); > > for (i=1;i<=5;i++) > { > scanf("%d",&a[i]); > sum+=a[i]; > } > > if (sum<s) > { > scanf("%s",ch); > printf("I'd rather not wear a shirt anyway...\n"); > continue; > } > > for (i=1;i<=s;i++) > { > switch (c[i][0]) > { > case 'S':no[i].x=1;break; > case 'M':no[i].x=2;break; > case 'L':no[i].x=3;break; > case 'X':no[i].x=4;break; > case 'T':no[i].x=5;break; > } > switch (c[i][1]) > { > case 'S':no[i].y=1;break; > case 'M':no[i].y=2;break; > case 'L':no[i].y=3;break; > case 'X':no[i].y=4;break; > case 'T':no[i].y=5;break; > } > } > > for (i=1;i<s;i++) //对每个人的要求按最小的号进行排序 > { > m=i; > min=no[i].x; > for (j=i+1;j<=s;j++) > if (no[j].x<min) > { > m=j; > min=no[j].x; > } > if (m!=i) > { > t=no[i].x; > no[i].x=no[m].x; > no[m].x=t; > t=no[i].y; > no[i].y=no[m].y; > no[m].y=t; > } > } > > flag=0; //判断是否满足条件 > for (i=1;i<=s;i++) > for (j=no[i].x;j<=no[i].y;j++) > if (a[j]) > { > a[j]--; > flag++; > break; > } > > if (flag!=s) > { > scanf("%s",ch); > printf("I'd rather not wear a shirt anyway...\n"); > } > else > { > scanf("%s",ch); > printf("T-shirts rock!\n"); > } > } > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator