2018.09.18测试

又是一天的神仙题呢,辣鸡南瓜只会T1还不知道这个做法的正确性orz

1.1
Conjugate
问题描述
在不存在的 noip day3 里,小 w ?到了一堆堆的谜题。
比如这题为什么会叫共轭?
他并不知道答案。
有 n 堆谜题,每堆有 a i 个,小 w 每次从剩下的谜题中选择一个,然后把所在的那一堆谜题
全部丢掉。
小 w 期望多少次后丢掉第一堆?
1.2
输入格式
一行一个整数 n。
一行 n 个整数,表示 a i 。
1.3
输出格式
一行一个数表示期望,误差不得超过 10 −6 。
1.4
样例输入
2
1 1
1.5
样例输出
1.5
1.6
数据规模与约定
对于 20% 的数据,n ≤ 10。
对于 40% 的数据,n ≤ 1000。
对于另外 20% 的数据,a i = 1。
对于 100% 的数据,n ≤ 10 5 , 1 ≤ a i ≤ 10 9 。

期望可加性,考虑每一堆比第一堆先抽到的概率
每次丢掉一堆可以等价的变为,每次抽到一个把这一堆标记
为访问过,如果抽到一个访问过的,那么把它丢掉
显然别的堆不影响答案
第 i 堆的贡献是ai/(a1+ai)

然后是code:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;

const int maxn=1e5+10;
int n;
double ans,a[maxn];

int read()
{
	int xx=0,kk=1;char ch=' ';
	while(!isdigit(ch)){ch=getchar();if(ch=='-')kk=-1;}
	while(isdigit(ch)){xx=xx*10+ch-'0';ch=getchar();}
	return kk*xx;
}

int main()
{
	freopen("conjugate.in","r",stdin);
	freopen("conjugate.out","w",stdout);
	n=read(); 
	ans=1.0;a[1]=read();
	for(int i=2;i<=n;++i)
		a[i]=read(),ans+=((a[i])/(a[i]+a[1]));
	printf("%.10lf",ans);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40942982/article/details/82763268
今日推荐