地址: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

 #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 ;
}

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. 漫游Kafka实战篇之搭建Kafka运行环境(2)

    接下来一步一步搭建Kafka运行环境. Step 1: 下载Kafka 点击下载最新的版本并解压. > tar -xzf kafka_2.9.2-0.8.1.1.tgz > cd kafk ...

  2. [转]ODBC编程指南

    DM4 ODBC编程指南本章结合DM4数据库的特点,比较全面系统的介绍ODBC的基本概念以及DM4 ODBC DRIVER的使用方法,以便用户更好地使用DM4 ODBC编写应用程序.ODBC提供给你访 ...

  3. PHP项目中经常用到的无限极分类函数

    //无限极分类函数调用 function getTree($data,$parent_id = 0,$dept_level = 0){ static $tree = []; foreach ($dat ...

  4. 第十五篇:C程序的存储空间布局

    前言 C语言程序的执行必定需要耗费一定的资源,也就是说,程序在计算机内部的映像不可能就单单代码. 本文将讲解C语言程序在计算机内部的存在方式. 程序存储空间 1. 正文段:程序的机器指令部分 2. 初 ...

  5. 《C++ Primer Plus》学习笔记——C++程序创建到运行的整个过程

    当你编写了一个C++,如何让它运行起来呢?具体的步骤取决于计算机环境和使用的C++编译器,但大体如下: 1.使用文本编辑器编写程序,并将其保存到文件中,这个文件就是程序的源代码. 2.编译源代码.这意 ...

  6. delay()延迟

    jquery的delay()方法: delay() 方法对队列中的下一项的执行设置延迟. 封装方法: $.fn.fadeInWithDelay = function(){ var delay = 0; ...

  7. 如何用原生js替换字符串中的某个字符(或字符串)为指定的字符串?

    <html> <head><title>我的第一个 HTML 页面</title></head><script type=" ...

  8. spring boot 加载jsp

    1.spring boot启动类继承SpringBootServletInitializer ,并且重写configure方法 package com.springapp.mvc;import jav ...

  9. Windows下使用Gflags检查内存越界

    环境:windows xp. vs2005 Gflags可用于查找内存越界的问题. 访问一块申请的内存时,当访问的地址超过申请的范围时,就发生了内存越界的问题. 编写测试程序MemoryOverflo ...

  10. /proc/iomem和/proc/ioports对应的fops

    /proc/iomem和/proc/ioports对应的fops static int __init ioresources_init(void) {     struct proc_dir_entr ...