Uva311-packets (Greedy)

Source: Internet
Author: User

Question: 311-packets


The number of boxes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6 is given. Now there are several boxes 6*6, ask the minimum number of boxes that can be used to pack a given box.


Solution: For 6*6 boxes, each of them consumes one box.

For 5*5 boxes, 11 more 1*1 boxes can be installed.

For 4*4 boxes, 5 2*2 boxes can be installed after this is installed, and then 2*2 boxes can be supplemented with 1*1.

3x3 boxes:

1 3*3 box, 5 2*2 boxes, 7 1*1;

Same appeal format: 2 3 6

3 1 5

If two is required, 1 is used.


Code:

# Include <stdio. h> const int n = 6; int Packets [N]; // fill in the Void need () {If (Packets [1] <0) of 2*2) {Packets [0] + = Packets [1] * 4; Packets [1] = 0 ;}// determine the special situation of 3*3 void judge (int, int B) {Packets [1]-= A; Packets [0]-= B; need ();} int solve () {int sum = Packets [5]; int temp; For (INT I = N-2; I> = 1; I --) {if (I = 4) {sum + = Packets [I]; packets [0]-= 11 * Packets [I];} else if (I = 3) {sum + = Packets [I]; Pack ETS [1]-= Packets [I] * 5; need ();} else if (I = 2) {sum + = Packets [I]/4; packets [I] % = 4; If (Packets [I] = 3) {sum ++; Judge (1, 5);} else if (Packets [I] = 2) {sum ++; Judge (3, 6);} else if (Packets [I] = 1) {sum ++; Judge (5, 7 );}} else {temp = Packets [1] * 4; If (Packets [0]> 0) temp + = Packets [0]; sum + = (temp + 35) /36 ;}} return sum;} int main () {int count; while (1) {COUNT = 0; For (INT I = 0; I <N; I ++) {Scanf ("% d", & Packets [I]); count + = Packets [I];} If (! Count) break; printf ("% d \ n", solve () ;}return 0 ;}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.