Luck Competition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1051 Accepted Submission(s): 646
If you are given a chance to know how many people are participating the competition and what their numbers are, calculate the highest number with the highest probability to win assuming that you're joining the competition.
Each test case begins with an integer N(1<N≤100), denoting the number of participants. And next line contains N−1 numbers representing the numbers chosen by other participants.
#include <bits/stdc++.h>
using namespace std;
int t, n, sum;
int a[1001];
int judge(int k){
//printf("k = %d %f\n", k, (double)(k+sum)/n*2/3);
if((double)(k+sum)/n*2/3 < k) return 0;
return 1;
}
int main(){
scanf("%d", &t);
while(t--){
scanf("%d", &n);
sum = 0;
for(int i = 1; i < n; i++){
scanf("%d", &a[i]);
sum += a[i];
}
int l = 0, r = 100, ans;
while(l <= r){
int mid = (l+r)>>1;
if(judge(mid)) ans = mid, l = mid+1;
else r = mid-1;
}
int cnt = 1;
for(int i = 1; i < n; i++){
if(a[i] == ans) cnt++;
}
printf("%d %.2f\n", ans, 1.0/cnt);
}
}