Poj 1017

传送门:http://poj.org/problem?id=1017

六种正方形盒子边长分别为1~6,放入6*6的包裹中,求最小的包裹数

 1 #include<iostream>
 2 using namespace std;
 3 int main(){
 4     int pro[6];
 5     int sum;
 6     int last51;
 7     int last41,last42;
 8     int last31,last32;
 9     int last21;
10     bool flag=true;
11     while(cin>>pro[0]){
12         for(int i=1;i<6;i++){
13             cin>>pro[i];
14         }
15         if(!pro[0]&&!pro[1]&&!pro[2]&&!pro[3]&&!pro[4]&&!pro[5]){
16             break;
17         }
18         sum=0;
19         last51=0;
20         last41=0;
21         last42=0;
22         last31=0;
23         last32=0;
24         last21=0;
25         sum+=pro[5];
26         sum+=pro[4];
27         last51=pro[4]*11; 
28         sum+=pro[3];
29         last42=pro[3]*5;
30         last41=pro[3]*20;
31         sum+=(pro[2]/4); 
32         if(pro[2]%4){
33             sum++;
34         }
35         if(pro[2]%4==0){
36             last32=0;
37             last31=0;
38         } 
39         else if(pro[2]%4==1){
40             last32=5;
41             last31=27;
42         } 
43         else if(pro[2]%4==2){
44             last32=3;
45             last31=18;
46         } 
47         else if(pro[2]%4==3){
48             last32=1;
49             last31=9;
50         } 
51         if(last42>=pro[1]){
52             last41-=4*pro[1];
53         }
54         else{
55             last41=0;
56             pro[1]-=last42;
57             if(last32>=pro[1]){
58                 last31-=4*pro[1];
59             }
60             else{
61                 last31-=4*last32;
62                 pro[1]-=last32;
63                 sum+=pro[1]/9;
64                 if(pro[1]%9){
65                     sum++;
66                 }
67                 last21=4*(9-pro[1]%9);
68             }
69         }
70         if(pro[0]>(last51+last41+last31+last21)){
71             sum+=((pro[0]-(last51+last41+last31+last21))/36);
72             if((pro[0]-(last51+last41+last31+last21))%36){
73                 sum++;
74             }
75         }
76         if(flag){
77             flag=false;
78         }
79         else{
80             cout<<endl;
81         }
82         cout<<sum;
83     }
84 } 

 

posted @ 2017-04-18 16:30  水野玛琳  阅读(130)  评论(0编辑  收藏  举报