hdoj-5704-Luck Competition
2016-06-02 20:11
393 查看
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
3
4
1 2 3
4
1 1 2
4
20 30 40
[align=left]Sample Output[/align]
1 0.50
0 1.00
18 1.00
简单数学题啊,妈个鸡,想了
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 105;
const int M = 15;
int c
;
int main()
{
int t,n,i,sum,x;
scanf("%d",&t);
while(t--)
{
sum=0;
memset(c,0,sizeof(c));
scanf("%d",&n);
for(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));
}
return 0;
}
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
3
4
1 2 3
4
1 1 2
4
20 30 40
[align=left]Sample Output[/align]
1 0.50
0 1.00
18 1.00
简单数学题啊,妈个鸡,想了
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 105;
const int M = 15;
int c
;
int main()
{
int t,n,i,sum,x;
scanf("%d",&t);
while(t--)
{
sum=0;
memset(c,0,sizeof(c));
scanf("%d",&n);
for(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));
}
return 0;
}
相关文章推荐
- IOS动画机制
- HDU max sum(最大子序列之和)
- linux (Fedora 23)初期个性化设置
- 母女二人
- C++中常用特殊符号简介(& , * , : , :: , ->)
- 二分查找算法
- Executors.newSingleThreadExecutor的一些坑
- 网络爬虫的简单例子
- Thread类的使用
- C/C++中time.h
- android 学习笔记十二 监听键盘状态
- DPL,RPL,CPL 之间的联系和区别
- MySQL远程登录设置
- CSS角度单位(deg)
- 触摸UITextView找到该触摸点的文字
- adb shell input swipe 1000 100 0 0
- PHP小数取整
- 【跟着子迟品 underscore】如何优雅地写一个『在数组中寻找指定元素』的方法
- bgp笔记
- HNACM9热身赛