Codeforces Round #399 (Div. 1 + Div. 2, combined) D题Jon and Orbs(dp)解题报告
2017-02-23 11:11
375 查看
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.
Input
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
Output q lines. On i-th of them output single integer — answer for i-th query.
Example
Input
Output
Input
Output
, 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.
Input
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
Output q lines. On i-th of them output single integer — answer for i-th query.
Example
Input
1 1 1
Output
1
Input
2 2 1 2
Output
2 2 用二维数组 a i,j 表示第i天,已有j种不同的概率。很容易推得递推公式 (a i,j)= (a i-1,j )* j/k if(j>1) += (a i,j-1)* (k-j+1)/k
1 #include <iostream> 2 //#include<bits/stdc++.h> 3 #include <stack> 4 #include <queue> 5 #include <map> 6 #include <set> 7 #include <cstdio> 8 #include <cstring> 9 #include <algorithm> 10 #include <math.h> 11 using namespace std; 12 typedef long long ll; 13 typedef unsigned long long ull; 14 const double ds=0.0000001; 15 double pos[10000][1002]; 16 int k,q; 17 int main() 18 { 19 scanf("%d %d",&k,&q); 20 memset(pos,0,sizeof(pos)); 21 pos[1][1]=1.0; 22 int i,j; 23 int tem; 24 for(i=2;;i++) 25 { 26 for(j=1;j<=k;j++) 27 { 28 pos[i][j]=pos[i-1][j]*(double)j/(double)k; 29 if(j>1) 30 pos[i][j]+=pos[i-1][j-1]*(double)(k-j+1)/(double)k; 31 } 32 if(pos[i][k]>=0.5) 33 break; 34 } 35 for(i=1;i<=q;i++) 36 { 37 scanf("%d",&tem); 38 for(j=1;;j++) 39 { 40 if(pos[j][k]*2000.0-(double)tem>=-ds) 41 break; 42 } 43 printf("%d\n",j); 44 } 45 }
相关文章推荐
- 【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) 解题报告
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
- 【解题报告】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
- Codeforces Round #396 (Div. 2) E题Mahmoud and a xor trip(树状dp)解题报告
- 解题报告:Codeforces Round #433 (Div. 1) D. Michael and Charging Stations (DP)
- Codeforces Round #396 (Div. 2) C题Mahmoud and a Message(dp)解题报告
- Codeforces Round #235 (Div. 2) D. Roman and Numbers 解题报告(状态压缩)
- Codeforces Round #365 (Div. 2) Problem D.Mishka and Interesting sum 解题报告
- Monkey and Banana(HDU 1069)解题报告(DP - 滚动数组)
- codeforces 768 D Jon and Orbs(概率dp)
- Codeforces Round #393 (Div. 2) E题Nikita and stack(线段树)解题报告
- codeforces-768D-Jon and Orbs(概率DP)
- Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 解题报告
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number
- poj 2288 Islands and Bridges解题报告-状态压缩dp
- Codeforces Round #297 (Div. 2) C. Ilya and Sticks 解题报告
- Codeforces Round #383 (Div. 1) Problem A. Arpa's loud Owf and Mehrdad's evil plan 解题报告
- 解题报告:Codeforces Round #381 (Div. 1)B. Alyona and a tree
- Codeforces Round #399 D. Jon and Orbs(概率dp,好题)