Monday, January 6, 2020

POJ.1017 Packets

Problem:
http://poj.org/problem?id=1017

Idea:
Start packing from bigger sized boxes.

Source:
 int c[6];  
 int x, y;  
 void solve()  
 {  
      int ans = 0;  
      //6*6  
      ans += c[5];  
      //5*5  
      ans += c[4];  
      c[0] = max(0, c[0] - 11 * c[4]);  
      //4*4  
      ans += c[3];  
      x = c[1];  
      c[1] = max(0, c[1] - 5 * c[3]);  
      if (c[1] == 0 && c[3]) {  
           c[0] = max(0, c[0] - (c[3]*20 - x * 4));  
      }  
      //3*3  
      ans += (c[2] / 4);  
      if (c[2] % 4 == 3) {  
           ans++;  
           if (c[1]) {  
                c[1]--;  
                c[0] = max(0, c[0] - 5);  
           }  
           else {  
                c[0] = max(0, c[0] - 9);  
           }  
      }  
      else if (c[2] % 4 == 2) {  
           ans++;  
           if (c[1] >= 3) {  
                c[1]-=3;  
                c[0] = max(0, c[0] - 6);  
           }  
           else {  
                x = c[1];  
                c[1] = 0;  
                c[0] = max(0, c[0] - (18 - x * 4));  
           }  
      }  
      else if (c[2] % 4 == 1) {  
           ans++;  
           if (c[1] >= 5) {  
                c[1] -= 5;  
                c[0] = max(0, c[0] - 7);  
           }  
           else {  
                x = c[1];  
                c[1] = 0;  
                c[0] = max(0, c[0] - (18 - x * 4));  
           }  
      }  
      //2*2  
      ans += (c[1] / 9);  
      if (c[1] % 9) {  
           ans++;  
           c[0] = max(0, c[0] - (36 - 4 * (c[1]%9)));  
      }  
      //1*1  
      if (c[0] % 36 == 0) {  
           ans += (c[0] / 36);  
      }  
      else {  
           ans += (1 + c[0] / 36);  
      }  
      cout << ans << endl;  
 }  
 int main()  
 {  
      while (1) {  
           int sum = 0;  
           for (int i = 0; i < 6; i++) {  
                cin >> c[i];  
                sum += c[i];  
           }  
           if (sum == 0) break;  
           solve();  
      }  
      return 0;  
 }  

No comments:

Post a Comment