poj1017Packets
关于数字的题我的确不擅长,可能是抽象思维的能力太差了,多动手画画也许会好些。
本以为这一题是DP,仔细分析之后才发现是模拟,原因是箱子之间的组合情况极其有限!
代码
1import java.io.*;
2import java.util.*;
3class Main
4{
5 static int am[] = new int[7];
6 static int cans;
7 public static void main(String[] args)
8 {
9 Scanner sc = new Scanner(System.in);
10
11 for(int i = 1; i <= 6; i++)
12 am[i] = sc.nextInt();
13 while(am[6] + am[1] + am[2] + am[3] + am[4] + am[5] != 0)
14 {
15 cans = 0;
16 cans += am[6];
17 put5();
18 put4();
19 put3();
20 put2();
21 put1();
22 System.out.println(cans);
23 for(int i = 1; i <= 6; i++)
24 am[i] = sc.nextInt();
25 }
26 }
27 private static void put5(){//put 25
28 cans += am[5];
29 am[1] -= am[5] * 11;
30 }
31 private static void put4(){
32 if(am[4] == 0)
33 return;
34 cans += am[4];
35 if(am[2] >= am[4] * 5)
36 {
37 am[2] -= am[4] * 5;
38 }
39 else
40 {
41 am[1] -= (am[4] * 20 - am[2] * 4);
42 am[2] = 0;
43 }
44 }
45 private static void put3(){
46 cans += (am[3] + 3) / 4;
47 int last3 = am[3] % 4;
48 if(last3 == 3)
49 {
50 if(am[2] >= 1)
51 {
52 am[2] -= 1;
53 am[1] -= 5;
54 }
55 else
56 {
57 am[1] -= 9;
58 }
59 }
60 else if(last3 == 2)
61 {
62 if(am[2] >= 3)
63 {
64 am[2] -= 3;
65 am[1] -= 6;
66 }
67 else
68 {
69 am[1] -= (6 + 4 * (3 - am[2]));
70 am[2] = 0;
71 }
72 }
73 else if(last3 == 1)
74 {
75 if(am[2] >= 5)
76 {
77 am[2] -= 5;
78 am[1] -= 7;
79 }
80 else
81 {
82 am[1] -= (7 + 4 * (5 - am[2]));
83 am[2] = 0;
84 }
85 }
86 }
87 private static void put2(){// put 4
88 cans += (am[2] + 8) / 9;
89 int t = am[2] % 9;
90 if(t > 0)
91 am[1] -= (36 - t * 4);
92 }
93 private static void put1(){
94 if(am[1] < 0)
95 am[1] = 0;
96 cans += (am[1] + 35) / 36;
97 }
98}
99
1import java.io.*;
2import java.util.*;
3class Main
4{
5 static int am[] = new int[7];
6 static int cans;
7 public static void main(String[] args)
8 {
9 Scanner sc = new Scanner(System.in);
10
11 for(int i = 1; i <= 6; i++)
12 am[i] = sc.nextInt();
13 while(am[6] + am[1] + am[2] + am[3] + am[4] + am[5] != 0)
14 {
15 cans = 0;
16 cans += am[6];
17 put5();
18 put4();
19 put3();
20 put2();
21 put1();
22 System.out.println(cans);
23 for(int i = 1; i <= 6; i++)
24 am[i] = sc.nextInt();
25 }
26 }
27 private static void put5(){//put 25
28 cans += am[5];
29 am[1] -= am[5] * 11;
30 }
31 private static void put4(){
32 if(am[4] == 0)
33 return;
34 cans += am[4];
35 if(am[2] >= am[4] * 5)
36 {
37 am[2] -= am[4] * 5;
38 }
39 else
40 {
41 am[1] -= (am[4] * 20 - am[2] * 4);
42 am[2] = 0;
43 }
44 }
45 private static void put3(){
46 cans += (am[3] + 3) / 4;
47 int last3 = am[3] % 4;
48 if(last3 == 3)
49 {
50 if(am[2] >= 1)
51 {
52 am[2] -= 1;
53 am[1] -= 5;
54 }
55 else
56 {
57 am[1] -= 9;
58 }
59 }
60 else if(last3 == 2)
61 {
62 if(am[2] >= 3)
63 {
64 am[2] -= 3;
65 am[1] -= 6;
66 }
67 else
68 {
69 am[1] -= (6 + 4 * (3 - am[2]));
70 am[2] = 0;
71 }
72 }
73 else if(last3 == 1)
74 {
75 if(am[2] >= 5)
76 {
77 am[2] -= 5;
78 am[1] -= 7;
79 }
80 else
81 {
82 am[1] -= (7 + 4 * (5 - am[2]));
83 am[2] = 0;
84 }
85 }
86 }
87 private static void put2(){// put 4
88 cans += (am[2] + 8) / 9;
89 int t = am[2] % 9;
90 if(t > 0)
91 am[1] -= (36 - t * 4);
92 }
93 private static void put1(){
94 if(am[1] < 0)
95 am[1] = 0;
96 cans += (am[1] + 35) / 36;
97 }
98}
99