• Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs


    地址: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
    output
    1
    input
    2 2
    1
    2
    output
    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-7;
    10 const double pi=acos(-1.0);
    11 const int K=1e6+7;
    12 const int mod=1e9+7;
    13 
    14 double dp[1050];
    15 int x,q,k,ans[1050];
    16 int main(void)
    17 {
    18     cin>>k>>q;
    19     dp[0]=1;
    20     for(int i=1;x<=1000;i++)
    21     {
    22         for(int j=k;j;j--)
    23             dp[j]=dp[j]*j/k+dp[j-1]*(k-j+1)/k;
    24         while(x<=1000 && dp[k]*2000>=x-eps)
    25             ans[x++]=i;
    26         dp[0]=0;
    27     }
    28     while(q--)
    29         scanf("%d",&x),printf("%d
    ",ans[x]);
    30     return 0;
    31 }
  • 相关阅读:
    RabbitMQ知识点整理2-相关概念介绍
    RabbitMQ知识点整理1-生产和消费消息
    Java自学-图形界面 Swing中的线程
    Java自学-图形界面 日期控件
    Java自学-图形界面 表格
    Java自学-图形界面 工具栏
    WebStorm 2020.2.3 破解(Mac,windows,Linux)
    消息队列的使用场景
    有关建立虚拟环境的总结
    性能测试-Locust分布式执行
  • 原文地址:https://www.cnblogs.com/weeping/p/6426588.html
Copyright © 2020-2023  润新知