Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
好纠结的一道题,感觉基本就是hard code,有一点点贪心的影子#include <cstdio> void put_one(int size, int* order, int* remain){ switch(size){ case 6: for(int i = 0;i < 6;i++) remain[i] = 0; order[5]--; break; case 5: for(int i = 1;i < 6;i++) remain[i] = 0; remain[0] = 11; order[4]--; break; case 4: for(int i = 2;i < 6;i++) remain[i] = 0; remain[1] = 5; remain[0] = 20; order[3]--; break; case 3: switch(remain[2]){ case 4: remain[2]--; remain[1] = 5; remain[0] = 27; order[2]--; break; case 3: remain[2]--; remain[1] = 3; remain[0] = 18; order[2]--; break; case 2: remain[2]--; remain[1] = 1; remain[0] = 9; order[2]--; break; case 1: remain[2]--; remain[1] = 0; remain[0] = 0; order[2]--; break; }break; case 2: remain[1]--; remain[0]-=4; order[1]--; break; case 1: remain[0]--; order[0]--; break; } } bool put(int* order, int* remain){ bool flag = false; for(int i = 5;i>=0;i--) while(order[i] && remain[i]){ put_one(i+1, order, remain); flag = true; } return flag; } void reset(int* remain){ remain[0] = 36; remain[1] = 9; remain[2] = 4; remain[3] = 1; remain[4] = 1; remain[5] = 1; } int main(int argc, char** argv) { int order[6]; int remain[6] = {36, 9, 4, 1, 1, 1}; int cnt = 1; while(1){ scanf("%d%d%d%d%d%d", &order[0], &order[1], &order[2], &order[3], &order[4], &order[5]); if(order[0] == 0 && order[1] == 0 && order[2] == 0 && order[3] == 0 && order[4] == 0 && order[5] ==0) break; while(order[0] || order[1] || order[2] || order[3] || order[4] || order[5]){ if(!put(order, remain)){ cnt++; reset(remain); } } printf("%d\n", cnt); cnt = 1; reset(remain); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator