"Python3" "greedy" hdu4296 buildings

Source: Internet
Author: User

Test instructions

n plates, each plate has weight and strength W and s, and PDV value (total weight above-the strength of the board) for some sort of stacking mode, the maximum value of PDV is the minimum value for which it represents the value to consider only two plates of the case: A and B, it is obvious that the following is more prone to damage than the above, so the following Suppose A is above, its PDV value = Pdvb = Wa-sb. Suppose B is above, its PDV value = Pdva = Wb-sa. The two values are then minimized, if a is small on the PDV, then WA-SB < Wb-sa, i.e. WA + SA < WB + sb. Similarly, if B is small on the PDV, WB + SB < WA + SA. Expansion to the case of N boards, any two adjacent plates do not affect the other board, so according to W+s from small to large, from top to bottom.
Try:    while True:        n = input ();        n = int (n);        a = [];        For I in range (0, N):            str = input (). split ();            A + = [[Int (str[0]), int (str[1])];        A = sorted (A, key = Lambda x:x[0]+x[1]);        SUMV = 0;        Maxx = 0;        For I in range (0, N):            maxx = Max (Maxx, Sumv-a[i][1]);            SUMV + = a[i][0];        Print (Maxx); except Eoferror:    Pass

"Python3" "greedy" hdu4296 buildings

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.