HDU 5704 Luck Competition

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(T≤10).

Each test case begins with an integer N(1

#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n, i;
        long long sum, a[105], x;
        cin>>n;
        sum = 0;
        for(i = 0; i < n-1; i++)
        {
            cin>>a[i];
            sum += a[i];
        }
        x = (2 * sum) / (3 * n - 2);
        sum = 1;
        for(i = 0; i < n-1; i++)
        {
            if(a[i] == x)
                sum++;
        }
        cout<<x<<" ";
        printf("%.2f\n", (double)1/sum);

    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42819248/article/details/82633326
今日推荐