HDU1353+贪心
注意精度。
1 /* 2 3 */ 4 #include<stdio.h> 5 #include<string.h> 6 #include<stdlib.h> 7 #include<algorithm> 8 #include<iostream> 9 #include<queue> 10 #include<map> 11 #include<math.h> 12 using namespace std; 13 typedef long long ll; 14 //typedef __int64 int64; 15 const int maxn = 105; 16 const int inf = 0x7fffffff; 17 const double pi=acos(-1.0); 18 const double eps = 1e-8; 19 20 int main(){ 21 double aim; 22 int a,b,c,d; 23 while( scanf("%lf%d%d%d%d",&aim,&a,&b,&c,&d)==5 ){ 24 if( aim>a*0.25+b*0.1+c*0.05+d*0.01 ){ 25 printf("NO EXACT CHANGE\n"); 26 continue; 27 } 28 int sum1,sum2,sum3,sum4; 29 sum1 = -1; 30 for( int i1=0;i1<=d;i1++ ){ 31 for( int i2=0;i2<=c;i2++ ){ 32 for( int i3=0;i3<=b;i3++ ){ 33 for( int i4=0;i4<=a;i4++ ){ 34 if( fabs(0.25*i4+0.1*i3+0.05*i2+0.01*i1-aim)<=eps ){ 35 sum1 = i4; 36 sum2 = i3; 37 sum3 = i2; 38 sum4 = i1; 39 break; 40 } 41 } 42 if( sum1!=-1 ) break; 43 } 44 if( sum1!=-1 ) break; 45 } 46 if( sum1!=-1 ) break; 47 } 48 if( sum1==-1 ) printf("NO EXACT CHANGE\n"); 49 else printf("%d %d %d %d\n",sum1,sum2,sum3,sum4); 50 } 51 return 0; 52 }
keep moving...