地址:http://codeforces.com/contest/768/problem/D
题目:
2 seconds
256 megabytes
standard input
standard output
Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall is full of dangers, he wants to know the minimum number of days he should wait before sending a ranger to collect the orbs such that the probability of him getting at least one of each kind of orb is at least , where ε < 10 - 7.
To better prepare himself, he wants to know the answer for q different values of pi. Since he is busy designing the battle strategy with Sam, he asks you for your help.
First line consists of two space separated integers k, q (1 ≤ k, q ≤ 1000) — number of different kinds of orbs and number of queries respectively.
Each of the next q lines contain a single integer pi (1 ≤ pi ≤ 1000) — i-th query.
Output q lines. On i-th of them output single integer — answer for i-th query.
1 1
1
1
2 2
1
2
2
2
思路:
概率dp,dp[i][j]表示i天后获得j种不同魔法球的概率
dp[i][j]=dp[i-1][j]*(k-j)/k+dp[i][j-1]*(k-j+1)/k;
因为概率至少大于0.5,所以不超过10000天。
因为有多次询问所以需要先预处理出所有答案。
参考:http://blog.csdn.net/johsnows/article/details/56289552
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; double dp[];
int x,q,k,ans[];
int main(void)
{
cin>>k>>q;
dp[]=;
for(int i=;x<=;i++)
{
for(int j=k;j;j--)
dp[j]=dp[j]*j/k+dp[j-]*(k-j+)/k;
while(x<= && dp[k]*>=x-eps)
ans[x++]=i;
dp[]=;
}
while(q--)
scanf("%d",&x),printf("%d\n",ans[x]);
return ;
}