zoukankan      html  css  js  c++  java
  • Codeforces Round #399 (Div. 1 + Div. 2, combined) D题Jon and Orbs(dp)解题报告

    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.

    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
    ",j);
    44     }
    45 }
    
    
  • 相关阅读:
    左耳听风笔记之一
    富爸爸穷爸爸 -- 笔记
    Aruba无线控制器常用操作
    接入交换机办公网常用配置
    核心交换机办公网常用配置
    FortiGate防火墙办公网常用配置
    去掉深信服上网认证页面里的“修改密码”
    深信服上网行为管理短信认证多用户登录问题
    深信服上网行为管理配置跨三层MAC识别
    深信服上网行为管理实现一次认证成功之后连续3天无流量通过才再次认证
  • 原文地址:https://www.cnblogs.com/quintessence/p/6432556.html
Copyright © 2011-2022 走看看