Poj2014-simulation-water Question 1a

Source: Internet
Author: User

The question is relatively simple, not to mention, that is, to put the rectangle in the box according to the question (the maximum width of the box is given). If you cannot put it down, put down a line. Note that it cannot be rotated here, which is the reason for the simulation of water questions, and it is not allowed to find the maximum or minimum, that is, to simulate the final state. It cannot be rotated and can be placed directly.

 

Code:

# Include <stdio. h> # include <stdlib. h> # include <string. h> # define min (a, B) (a <B? A: B) # define max (A, B) (A> B? A: B) int maxwidth; int main () {While (scanf ("% d", & maxwidth) {int W, H; int wnow = 0, hnow = 0; // the width and height of all items in the current box, initially 0int hmax = 0; // The maximum int wmax = 0 for each row; // The widest value of all rows while (1) {scanf ("% d", & W, & H ); if (W =-1 & H =-1) {break;} If (W> maxwidth-wnow) // if the current part cannot be placed in the current row, then, you can only put it in the next row {Hnow + = hmax; // so high will increase the maximum value of the previous row // note that this block will become the first wnow = W in the next row; // The current row width is the block width hmax = H; // the maximum height of the row is initialized as the block height} else // If the row can be placed, then this block is placed in the row {hmax = max (hmax, H); // the maximum value of the row is updated wnow + = W; // The current width value is updated wmax = max (wmax, wnow); // obtain the widest value of all rows before the current block} printf ("% d x % d \ n", wmax, Hnow + hmax ); // output the widest value of all rows, and add hmax} return 0;} to the previous Hnow row ;}

 

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.