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)