admin管理员组

文章数量:1530062

Problem Description Participants of the Luck Competition choose a non-negative integer no more than 100 in their mind. After choosing their number, let  K  be the average of all numbers, and  M  be the result of  K×23 . Then the lucky person is the one who choose the highest number no more than  M . If there are several such people, the lucky person is chosen randomly.

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.
 
Input There are several test cases and the first line contains the number of test cases  T(T10) .

Each test case begins with an integer  N(1<N100) , denoting the number of participants. And next line contains  N1  numbers representing the numbers chosen by other participants.

 
Output For each test case, output an integer which you have chosen and the probability of winning (round to two digits after the decimal point), seperated by space.

 
Sample Input
  
  
   
   3
4
1 2 3
4
1 1 2
4
20 30 40
  
  
 
Sample Output
  
  
   
   1 0.50
0 1.00

   
   

18 1.00

列个方程求解。。

#include<stdio.h>
#include<string.h>
using namespace std;
int c[1003];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        memset(c,0,sizeof(c));
        int x=0,sum=0;
        for(int i=1;i<n;i++)
        {
            scanf("%d",&x);
            c[x]++;
            sum+=x;
        }
        x=2*sum/ (3*n-2);
        printf("%d %.2f\n",x,1.0/(c[x]+1));
    }
}


本文标签: hduLuck水题competition