地址:http://codeforces.com/contest/768/problem/D

题目:

D. Jon and Orbs
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

First line consists of two space separated integers kq (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.

Examples
input
  1. 1 1
    1
output
  1. 1
input
  1. 2 2
    1
    2
output
  1. 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

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define MP make_pair
  6. #define PB push_back
  7. typedef long long LL;
  8. typedef pair<int,int> PII;
  9. const double eps=1e-;
  10. const double pi=acos(-1.0);
  11. const int K=1e6+;
  12. const int mod=1e9+;
  13.  
  14. double dp[];
  15. int x,q,k,ans[];
  16. int main(void)
  17. {
  18. cin>>k>>q;
  19. dp[]=;
  20. for(int i=;x<=;i++)
  21. {
  22. for(int j=k;j;j--)
  23. dp[j]=dp[j]*j/k+dp[j-]*(k-j+)/k;
  24. while(x<= && dp[k]*>=x-eps)
  25. ans[x++]=i;
  26. dp[]=;
  27. }
  28. while(q--)
  29. scanf("%d",&x),printf("%d\n",ans[x]);
  30. return ;
  31. }

Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs的更多相关文章

  1. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number

    地址:http://codeforces.com/contest/768/problem/C 题目: C. Jon Snow and his Favourite Number time limit p ...

  2. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    地址:http://codeforces.com/contest/768/problem/B 题目: B. Code For 1 time limit per test 2 seconds memor ...

  3. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch

    地址:http://codeforces.com/problemset/problem/768/A 题目: A. Oath of the Night's Watch time limit per te ...

  4. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)

    C题卡了好久,A掉C题之后看到自己已经排在好后面说实话有点绝望,最后又过了两题,总算稳住了. AC:ABCDE Rank:191 Rating:2156+37->2193 A.Oath of t ...

  5. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索

    A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

    打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> ...

  7. 【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    直接暴力dp就行……f(i,j)表示前i天集齐j种类的可能性.不超过10000天就能满足要求. #include<cstdio> using namespace std; #define ...

  8. 【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number

    发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了. 复杂度O(k*1024). #include<cstdio> #include<c ...

  9. 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...

随机推荐

  1. jQuery的end()方法使用详解

    end()方法的定义和用法: end()方法能够回到最近的一个"破坏性"操作之前,即将匹配的元素列表变为前一次的状态.如果没有破坏性操作将返回一个空集.破坏性操作的概念:指任何改变 ...

  2. MathType怎么编辑双箭头

    很多的数学相关工作者在写文章或论文的时候常常会用到数学公式编辑器.MathType就是一款深受大家欢迎的公式编辑器.很多的用户在使用过程中会用到双箭头符号来表示推理过程,但是怎么编辑又不知道,下面本教 ...

  3. Linux网卡命名enp3s0说明

    用了很多年Linux的我在升级Ubuntu 16.04之后竟然发现我的以太网卡的名字竟然不是eth0,变成了enp3s0,每次想要修改什么配置,都要先ifconfig查一下网卡名,真是让我很郁闷! 去 ...

  4. 81、去除标题栏 Activity 和 AppCompatActivity

    [Activity ] requestWindowFeature(Window.FEATURE_NO_TITLE); [AppCompatActivity] getSupportActionBar() ...

  5. 以打字形式展示placeholder的插件

    http://weber.pub/以打字形式展示placeholder的插件/197.html

  6. 【BZOJ4872】[Shoi2017]分手是祝愿 数学+期望DP

    [BZOJ4872][Shoi2017]分手是祝愿 Description Zeit und Raum trennen dich und mich. 时空将你我分开.B 君在玩一个游戏,这个游戏由 n ...

  7. Android 全局异常处理(三)

    用过安卓手机的用户以及安卓开发者们会时长碰到程序异常退出的情况,普通用户遇到这种情况,肯定非常恼火,甚至会骂一生垃圾软件,然后卸载掉.那么开发者们在开发过程中遇到这种情况给怎么办呢,当然,你不可能世界 ...

  8. cx_Oracle在sublime text里运行遇到 ImportError错误解决办法

    如果你装完cx_Oracle之后,命令行运行没错,但是在sublime text里运行, 就遇到这个错误: ImportError: dlopen(/Library/Python/2.7/site-p ...

  9. dreamweaver中Dw设置svn进行版本控制

    需要工具: VisualSVN dwcs5+ 点击查看教程

  10. 遇到的问题mongodb

    1.MongoNetworkError:failed to connect to server? 数据库没有启动,启动mongo数据库就好 2.有些东西真的是要做好记录的,单纯为了自己日后可以查阅比较 ...