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 <stdlib.h> #include <math.h> int ok; int m; struct coin{ int a; int b; double c; }map[1000]; int cmp(const void *a,const void *b) { struct coin *c=(coin *)a; struct coin *d=(coin *)b; return c->c>d->c?1:-1; } void find(int now,int x,int s) { int r,t; if(x==m) return; t=now/map[x].b; if(now-t*map[x].b!=0) for(r=t;r>=0;r--){ find(now-r*map[x].b,x+1,s+r*map[x].a); if(ok) return; } else{ ok=1; printf("The minimum amount of money in the piggy-bank is %d.\n",s+t*map[x].a); return; } } int main() { int a,b,c,i,n; scanf("%d",&n); while(n--) { scanf("%d%d",&a,&b); c=(int)fabs(b-a); scanf("%d",&m); for(i=0;i<m;i++){ scanf("%d%d",&map[i].a,&map[i].b); map[i].c=(double)map[i].a/(double)map[i].b; } qsort(map,m,sizeof(map[0]),cmp); ok=0; find(c,0,0); if(!ok) printf("This is impossible.\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator