POJ 1017

来源:互联网 发布:mac 中英文切换灯不亮 编辑:程序博客网 时间:2024/06/04 00:33
/*这题做的我心中上,有一万个草泥马。(用了一千个随机数测试,才知道自己的一部分代码出了逻辑错误,下次一定要注意一下本来简单的错误,我硬是找错误找了半天!) */#include <iostream>#include <fstream>#include <cstring>using namespace std;int main(){//freopen("a.txt", "r", stdin);   //输入重定向,输入数据将从in.txt文件中读取    //freopen("b.txt", "w", stdout);int flag[6];int count = 0;while(cin>>flag[0]>>flag[1]>>flag[2]>>flag[3]>>flag[4]>>flag[5] && flag[0]+flag[1]+flag[2]+flag[3]+flag[4]+flag[5]){count = 0;count = flag[5];if(flag[4] > 0){count += flag[4];int tempA = flag[4]*11;flag[0] -= tempA;}//printf("%d %d %d %d %d %d\n",flag[0],flag[1],flag[2],flag[3],flag[4],flag[5]);//printf("5count = %d\n",count);if(flag[3] > 0){count += flag[3];int tempB = flag[3] * 5;while(tempB){if(flag[1] > 0){--flag[1];--tempB;}else{break;}}int tempA = tempB * 4;flag[0] = flag[0] - tempA;}//printf("%d %d %d %d %d %d\n",flag[0],flag[1],flag[2],flag[3],flag[4],flag[5]);//printf("4count = %d\n",count);int tempA,tempB,tempC;if(flag[2] > 0){count += flag[2]/4;int tempC = flag[2]%4;if(tempC != 0){++count;}tempC = 4 - tempC;switch(tempC){case 1: if(flag[1] > 0){--flag[1];flag[0] -= 5;}else{flag[0] -= 9;}break;case 2:tempB = 3;while(tempB){if(flag[1] > 0){--flag[1];--tempB;}else{break;}}tempA = tempB * 4 + 6;flag[0] = flag[0] - tempA;break;case 3:tempB = 5;while(tempB){if(flag[1] > 0){--flag[1];--tempB;}else{break;}}tempA = tempB * 4 + 7;flag[0] -= tempA;default: ;}}//printf("%d %d %d %d %d %d\n",flag[0],flag[1],flag[2],flag[3],flag[4],flag[5]);//printf("3count = %d\n",count);if(flag[1] > 0 )  {count += flag[1]/9;tempB = flag[1]%9;if(tempB != 0){++count;tempA = (9-tempB) * 4;flag[0] -= tempA;}}//printf("%d %d %d %d %d %d\n",flag[0],flag[1],flag[2],flag[3],flag[4],flag[5]);//printf("2count = %d\n",count);if(flag[0] > 0){count += flag[0]/36;if(flag[0]%36 != 0){++count;}}//printf("%d %d %d %d %d %d\n",flag[0],flag[1],flag[2],flag[3],flag[4],flag[5]);//printf("1count = %d\n",count);printf("%d\n",count);}}