HDU-4974-a simple water problem (Greedy + evidentiary)

Source: Internet
Author: User

Question: n teams (n <= 100000), each team has a total score of AI (AI <= 1000000). Each team can score one point at most for each game, ask the minimum number of matches.

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4974

--> We should try our best to set the score of each game to 1: 1, so that we can achieve the minimum number of matches (not less than the score of a single team ).

Assume that the score for two matches is 1: 0,

1) A: B = 1: 0, C: D = 1: 0. In this case, you can arrange a: c = 1: 1. the same score can be obtained in only one field.

2) A: B = 1: 0, A: c = 1: 0, take another game D: E = 1: 1, then you can arrange a: D = 1: 1, A: E = 1: 1. the same score can be obtained in only two places.

Therefore, the score for one game is 1: 0 at most, and for other games, the score is 1: 1. Therefore, the result is = max (the highest score for a single team, (All scores and + 1)/2 )... (Note range: 10 ^ 5*10 ^ 6> 2 ^ 31-1)

For submission on virtual contest, you must enable and disable the input to avoid TLE ..

Scanf in HDU library 4974 can be used as an AC ..

#include <cstdio>int ReadInt(){    int ret = 0;    char ch;    while ((ch = getchar()) && ch >= '0' && ch <= '9')    {        ret = ret * 10 + ch - '0';    }    return ret;}int main(){    int T, N, a, kase = 0;    scanf("%d", &T);    getchar();    while (T--)    {        long long sum = 0;        long long ret = 0;        N = ReadInt();        while (N--)        {            a = ReadInt();            sum += a;            if (a > ret)            {                ret = a;            }        }        if (sum & 1)        {            sum++;        }        sum >>= 1;        if (sum > ret)        {            ret = sum;        }        printf("Case #%d: %I64d\n", ++kase, ret);    }    return 0;}


HDU-4974-a simple water problem (Greedy + evidentiary)

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.