Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 36663 | Accepted: 12207 |
Description
Input
Output
Sample Input
0 0 4 0 0 1 7 5 1 0 0 0 0 0 0 0 0 0
Sample Output
2 1
1 //代码一:----纯模拟的贪心算法,每次都尽最大的填充 2 #include<stdio.h> 3 int main() 4 { 5 int i,count; 6 int a[7]; 7 while(1) 8 { 9 for(i=1;i<=6;++i) 10 scanf("%d",&a[i]); 11 count=0; 12 if(a[1]||a[2]||a[3]||a[4]||a[5]||a[6]) 13 { 14 count=a[6]+a[5]+a[4]+(a[3]+3)/4; //(a[3]+3)/4可向上取绝对值 15 a[1]-=11*a[5]; 16 if(a[4]) 17 { 18 if(a[2]<5*a[4]) 19 { 20 a[1]-=20*a[4]-a[2]*4; 21 a[2]=0; 22 } 23 else 24 a[2]-=5*a[4]; 25 } 26 if(a[3]) 27 { 28 switch (a[3]%4) 29 { 30 case 0: 31 break; 32 case 1: 33 { 34 if(a[2]<5) 35 { 36 a[1]-=(27-a[2]*4); 37 a[2]=0; 38 } 39 else 40 { 41 a[2]-=5; 42 a[1]-=7; 43 } 44 break; 45 } 46 case 2: 47 { 48 if(a[2]<3) 49 { 50 a[1]-=(18-4*a[2]); 51 a[2]=0; 52 } 53 else 54 { 55 a[2]-=3; 56 a[1]-=6; 57 } 58 break; 59 } 60 default: 61 { 62 if(a[2]) 63 { 64 a[2]--; 65 a[1]-=5; 66 } 67 else 68 a[1]-=9; 69 break; 70 } 71 } 72 } 73 if(a[2]>0) 74 { 75 count+=(a[2]+8)/9; 76 a[1]-=36-(a[2]%9)*4; 77 } 78 if(a[1]>0) 79 count+=(a[1]+35)/36; 80 printf("%d\n",count); 81 } 82 else 83 break; 84 } 85 return 0; 86 } 87 88 //copy代码:------真短 89 #include<stdio.h> 90 int main() 91 { 92 int n,a,b,c,d,e,f,x,y; 93 int u[4]={0,5,3,1}; 94 while(1) 95 { 96 scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f); 97 if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0) 98 break; 99 n=d+e+f+(c+3)/4; 100 y=5*d+u[c%4]; 101 if(b>y) 102 n+=(b-y+8)/9; 103 x=36*n-36*f-25*e-16*d-9*c-4*b; 104 if(a>x) 105 n+=(a-x+35)/36; 106 printf("%d\n",n); 107 } 108 return 0; 109 }