浙江财经大学
信工学院ACM集训队

HDU 5704 Luck Competition

本文由 Ocrosoft 于 2016-08-16 14:43:09 发表

Luck Competition

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 376    Accepted Submission(s): 243

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<N≤100), denoting the number of participants. And next line contains N−1 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
 

Solution
题意:每个参赛人员选一个数字,最后将这些数字加起来,取平均值,并且乘以2/3,谁的数字和这个结果相同,这个人就是胜者。如果多人,随机选择。现在我们知道人数(包括自己)和别人的数字,我们要用那个数字参赛,胜率最高?

思路:假设我们选x,可以算出x = 2 * sum / (3 * n – 2)。

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cctype>
#include <climits>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ms(a) memset(a,0,sizeof(a))
typedef long long ll;
const int INF = INT_MAX;
const int MAXN = 200 + 10;
using namespace std;
int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		int n;
		int a[MAXN],sum=0;
		cin >> n;
		for (int i = 1; i < n; i++)
			cin >> a[i], sum += a[i];
		//假设自己选x,(sum+x)/n*2/3=x,化简x=2*sum/(3*n-2)
		int x = 2 * sum / (3 * n - 2);
		int cnt = 0;
		for (int i = 1; i < n; i++)
		{
			if (a[i] == x)cnt++;
		}
		printf("%d %.2lf\n", x, 1.0 / (cnt + 1));
	}
	return 0;
}

 

欢迎转载,请保留出处与链接。Ocrosoft » HDU 5704 Luck Competition

点赞 (0)or拍砖 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址