【HDOJ】1288 Hat's Tea

题目本身不难,但就是要搞清楚题目。

 1 #include <stdio.h>
 2 
 3 #define Fail(expression)\
 4     if (expression) {\
 5         printf("Hat cannot buy tea.\n");\
 6         continue;\
 7     }\
 8 
 9 int mymin(int a, int b) {
10     return a<b ? a:b;
11 }
12 
13 int main() {
14     int a, b, c, n, val[3];
15     int tmp;
16 
17     while (scanf("%d%d%d%d",&n,&a,&b,&c)!=EOF && (a||b||c||n)) {
18         tmp = a+b*5+c*10;
19         Fail(tmp < n);
20         Fail((a==0) && (b==0) && (n%10));
21         Fail((a==0) && (n%5));
22 
23         if (b) {
24             tmp = n%5;
25             Fail(tmp > a);
26             val[0] = tmp + mymin(n-tmp, (a-tmp)/5*5);
27             n -= val[0];
28 
29             tmp = n%10/5;
30             val[1] = tmp + mymin((n-tmp*5)/10*2, (b-tmp)/2*2);
31             n -= val[1]*5;
32         } else {
33             tmp = n%10;
34             Fail(tmp > a);
35             val[0] = tmp + mymin(n-tmp, (a-tmp)/10*10);
36             n -= val[0];
37             val[1] = 0;
38         }
39         val[2] = mymin(n/10, c);
40         printf("%d YiJiao, %d WuJiao, and %d ShiJiao\n", val[0], val[1], val[2]);
41     }
42 
43     return 0;
44 }

 

posted on 2014-04-13 17:42  Bombe  阅读(146)  评论(0编辑  收藏  举报

导航