Input Multiple test cases, process till end of the input. For each case, the first line contains a positive integers M, which is the number of groups. The i-th of the next M lines begins with a positive integer Bi representing the number of teams in the i-th group, followed by Bi nonnegative integers representing the score of each team in this group.number of test cases <= 10M<= 100B[i]<= 20000score of each team <= 20000
Output For each test case, output M lines. Output ``F" (without quotes) if the scores in the i-th group must be false, output ``T" (without quotes) otherwise. See samples for detail.
Sample Input 2 3 0 5 1 2 1 1
Sample Output F T
Source 2016 ACM/ICPC Asia Regional Dalian Online
Recommend wange2014 | We have carefully selected several similar problems for you: 6730 6729 6728 6727 6726 思路:这道题用的是巧妙的思路。假设从第一个人开始,到第b[i]个人,前面的人总是赢后面的人,那就有:每个人应得分数分别为 2 * (n - 1), 2 *(n - 2), 2 * (n - 3) .... 0。将实际值从大到小排序,如果(理论值) - (实际值)> 0,说明这个人有输了或者平了的记录;如果(理论值) - (实际值)= 0,说明莫得毛病;如果(理论值) - (实际值)< 0,说明这个情况时错误的。将所有的(理论值) - (实际值)相加,结果一定为0,若不为0,则为错误的情况。 #include<bits/stdc++.h> using namespace std; #define ll long long const int inf = 0x3f3f3f3f; const int mod = 1000000007; const int maxn = 10000 + 8; int m, b, num[20000 + 8], sum[20000 + 8]; int main() { while(~scanf("%d", &m)) { while(m--) { scanf("%d", &b); for(int j = 0; j < b; j++) { scanf("%d", &num[j]); sum[j] = 2 * j; } sort(num, num + b, greater<int>()); sort(sum, sum + b, greater<int>()); bool flag = 0; for(int j = 0; j < b; j++) sum[j] -= num[j]; int s = 0; for(int j = 0; j < b; j++) { s += sum[j]; if(s < 0) { flag = 1; break; } } if(s == 0 && !flag) printf("T\n"); else printf("F\n"); } } return 0; }
转载于:https://www.cnblogs.com/RootVount/p/11587504.html
相关资源:JAVA上百实例源码以及开源项目