Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么会WA?

Posted by sunflowwer at 2006-08-27 23:13:06 on Problem 1384
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator