HDU1288+枚举

虽然题意简单,但是注意的细节还是不少。

1、必须满足能刚好付这么多钱。

2、尽可能先把1毛的用完

3、在2的基础上把5毛的用完

4、用10的时候,保证sum是10的倍数,否则先去掉5个1毛,没有1毛再去5毛。。。

View Code
 1 #include<stdio.h>

 2 int main(){

 3     int  sum,x1,x5,x10;

 4     int  a,b,c;

 5     while( scanf("%d%d%d%d",&sum,&x1,&x5,&x10)!=EOF && ( sum||x1||x5||x10) ){

 6         a = b = c = 0;

 7         if( (sum%5)>x1 ){

 8             printf("Hat cannot buy tea.\n");

 9             continue;

10         }    

11         a = sum%5;

12         sum -= a;

13         x1 -= a;

14         if( sum<=x1 ){

15             a += sum;

16             printf("%d YiJiao, %d WuJiao, and %d ShiJiao\n",a,b,c);

17             continue;

18         }

19         x1/=5;

20         sum -= x1*5;

21         a += 5*x1;

22         if( sum<=5*x5 ){

23             b += sum/5;

24             printf("%d YiJiao, %d WuJiao, and %d ShiJiao\n",a,b,c);

25             continue;

26         }

27         sum -= 5*x5;

28         b = x5;

29         if( sum%10==0 ){

30             if( sum<=10*x10 ){

31                 c += sum/10;

32                 printf("%d YiJiao, %d WuJiao, and %d ShiJiao\n",a,b,c);

33                 continue;

34             }

35             else{

36                 printf("Hat cannot buy tea.\n");

37                 continue;

38             }

39         }

40         else{

41             if( b>0 )

42                 b--;

43             else

44                 if( a>=5 )

45                     a-=5;

46                 else{

47                      printf("Hat cannot buy tea.\n");

48                      continue;

49                 }

50             sum+=5;

51             if( sum<=10*x10 ){

52                 c = sum/10;

53                 printf("%d YiJiao, %d WuJiao, and %d ShiJiao\n",a,b,c);

54                 continue;

55             }

56             else{

57                 printf("Hat cannot buy tea.\n");

58                 continue;

59             }

60         }

61     }

62     return 0;

63 }

 

你可能感兴趣的:(HDU)