POJ1017

来源:互联网 发布:sql语句获得当前时间 编辑:程序博客网 时间:2024/04/29 02:52

 题目:http://acm.pku.edu.cn/JudgeOnline/problem?id=1017

 思路:从大到小放,注意每次往空里面放2*2和1*1的箱子

 

  1. import java.util.Scanner;
  2. public class Main {
  3.     int a;
  4.     int b;
  5.     int c;
  6.     int d;
  7.     int e;
  8.     int f;
  9.     int packets;
  10.     int t;
  11.     public Main() {
  12.         Scanner scan = new Scanner(System.in);
  13.         a = scan.nextInt();
  14.         b = scan.nextInt();
  15.         c = scan.nextInt();
  16.         d = scan.nextInt();
  17.         e = scan.nextInt();
  18.         f = scan.nextInt();
  19.         while (a != 0 || b != 0 || c != 0 || d != 0 || e != 0 || f != 0) {
  20.             // 6*6
  21.             packets = f;
  22.             // 5*5
  23.             packets += e;
  24.             a -= 11 * e;
  25.             // 4*4
  26.             packets += d;
  27.             if (b >= 5 * d) {
  28.                 b -= 5 * d;
  29.             } else {
  30.                 t = 5 * d - b;
  31.                 b = 0;
  32.                 a -= 4*t;
  33.             }
  34.             // 3*3
  35.             packets += c / 4;
  36.             t = c % 4;
  37.             if (t != 0) {
  38.                 packets += 1;
  39.                 if (t == 1) {
  40.                     if (b >= 5) {
  41.                         b -= 5;
  42.                         a -= 7;
  43.                     } else if (b >= 0) {
  44.                         a -= (36 - 9 - 4 * b);
  45.                         b = 0;
  46.                     }
  47.                 } else if (t == 2) {
  48.                     if (b >= 3) {
  49.                         b -= 3;
  50.                         a -= 6;
  51.                     } else if (b >= 0) {
  52.                         a -= (36 - 18 - 4 * b);
  53.                         b = 0;
  54.                     }
  55.                 } else if (t == 3) {
  56.                     if (b >= 1) {
  57.                         b -= 1;
  58.                         a -= 5;
  59.                     } else if (b >= 0) {
  60.                         a -= (36 - 27 - 4 * b);
  61.                         b = 0;
  62.                     }
  63.                 }
  64.             }
  65.             // 2*2
  66.             if (b > 0) {
  67.                 packets += b / 9;
  68.                 t = b % 9;
  69.                 if (t != 0) {
  70.                     packets += 1;
  71.                     a -= 36 - 4 * t;
  72.                 }
  73.             }
  74.             // 1*1
  75.             if (a > 0) {
  76.                 packets += a / 36;
  77.                 t = a % 36;
  78.                 if (t != 0) {
  79.                     packets += 1;
  80.                 }
  81.             }
  82.             System.out.println(packets);
  83.             a = scan.nextInt();
  84.             b = scan.nextInt();
  85.             c = scan.nextInt();
  86.             d = scan.nextInt();
  87.             e = scan.nextInt();
  88.             f = scan.nextInt();
  89.         }
  90.     }
  91.     public static void main(String[] args) {
  92.         new Main();
  93.     }
  94. }
原创粉丝点击