题目链接:http://hihocoder.com/problemset/problem/1489?sid=1587434

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Little Hi is playing a video game. Each time he accomplishes a quest in the game, Little Hi has a chance to get a legendary item.

At the beginning the probability is P%. Each time Little Hi accomplishes a quest without getting a legendary item, the probability will go up Q%. Since the probability is getting higher he will get a legendary item eventually.

After getting a legendary item the probability will be reset to ⌊P/(2I)⌋% (⌊x⌋ represents the largest integer no more than x) where I is the number of legendary items he already has. The probability will also go up Q% each time Little Hi accomplishes a quest until he gets another legendary item.

Now Little Hi wants to know the expected number of quests he has to accomplish to get N legendary items.

Assume P = 50, Q = 75 and N = 2, as the below figure shows the expected number of quests is

2*50%*25% + 3*50%*75%*100% + 3*50%*100%*25% + 4*50%*100%*75%*100% = 3.25

输入

The first line contains three integers PQ and N.

1 ≤ N ≤ 106, 0 ≤ P ≤ 100, 1 ≤ Q ≤ 100

输出

Output the expected number of quests rounded to 2 decimal places.

样例输入
50 75 2
样例输出
3.25

参考题解https://blog.csdn.net/sinat_26253653/article/details/68937034?utm_source=blogxgwz1
https://blog.csdn.net/BuptZhengChaoJie/article/details/69831275?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param坑的地方:
1)审题:每次未获得时,增加q,是在上次成功的概率p上增加q,所以是p+q,而不是1-p+q
2)dfs深搜模拟树的结构会超时
3)正确思路是,数学思想,获得两个物品(先获得物品1,在拿到1的基础上再获得物品2)的期望 = 先获得第一个物品的期望 + 获得第一个物品的基础上拿到物品2
的期望,参考题解第二个
4)在写代码时,谨慎使用double,注意p每次除以2取整数,所以可能提前为0了

AC代码,仅供参考:
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std; int n,p,q;
double result=0; int main()
{
cin>>p>>q>>n;
double current_p = p/100.0;
for(int i=1;i<=n;i++)
{
double accumulate_p = 1.0, sp = current_p; //sp = successful probability
int count = 1;
double e = 0;
while(1)
{
e += count*accumulate_p* sp;
if(sp>=1.0)
break;
accumulate_p *= (1-sp);
sp += q/100.0;
count++; if(sp>=1.0)
sp = 1.0;
}
result +=e ; p = p/2;
current_p = p/100.0;
} printf("%.2f",result); return 0;
}

hihocoder 1489(微软2017, 数学,模拟)的更多相关文章

  1. hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...

  2. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  3. hihocoder1489 Legendary Items (微软2017年预科生计划在线编程笔试)

    http://hihocoder.com/problemset/problem/1489 笔试题第一道,虽然说第一道都很水,但是我感觉这题不算特别水把..这道题我就卡住了我记得,tle,最后只有30分 ...

  4. 【微软2017年预科生计划在线编程笔试 A】Legendary Items

    [题目链接]:https://hihocoder.com/problemset/problem/1489 [题意] 每轮游戏; 你一开始有p的概率获得超神标记; 如果这轮游戏你没获得超神标记; 那么你 ...

  5. hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...

  6. 【hihocoder 1039 字符串消除】模拟

    题目链接:http://hihocoder.com/problemset/problem/1039 题意:给定一个只由{A, B, C}组成的字符串s,长度为n, 故包含n+1个空隙:现要求在某个空隙 ...

  7. 【微软2017年预科生计划在线编程笔试 B】Tree Restoration

    [题目链接]:https://hihocoder.com/problemset/problem/1490 [题意] 给你一棵树的以下信息: 1.节点个数 2.给出树的每一层从左到右的顺序每个节点的编号 ...

  8. 【微软2017年预科生计划在线编程笔试第二场 B】Diligent Robots

    [题目链接]:http://hihocoder.com/problemset/problem/1498 [题意] 一开始你有1个机器人; 你有n个工作; 每个工作都需要一个机器人花1小时完成; 然后每 ...

  9. 【微软2017年预科生计划在线编程笔试第二场 A】Queen Attack

    [题目链接]:http://hihocoder.com/problemset/problem/1497 [题意] 给你n个皇后; 然后问你其中能够互相攻击到的皇后的对数; 皇后的攻击可以穿透; [题解 ...

随机推荐

  1. 测试_QTP原理

    QTP是基于GUI界面的自动化测试工具,用于系统的功能测试.   QTP录制的是鼠标和键盘的消息.QTP录制回放时基于windows操作系统的消息机制.QTP在录制时监听应用程序的消息,监听到之后把消 ...

  2. [LeetCode题解]109. 有序链表转换二叉搜索树 | 快慢指针 + 递归

    题目描述 给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1. 示例: 给定的有序链表: ...

  3. Linux提权(持续更新)

    利用/etc/passwd提权 个人认为,这种提权方式在现实场景中难以实现,条件太过苛刻,但是建立Linux下的隐藏账户是个不错的选择,灵感来自:https://www.hackingarticles ...

  4. 各种有趣vbs,bat脚本

    短信轰炸.vbs Dim btn,ie Set ie = WScript.CreateObject("InternetExplorer.Application") ie.Visib ...

  5. Xcode6在ios7上编译framework报错

    错误描述: dyld: Symbol not found: _OBJC_CLASS_$_UIPresentationController Referenced from: /var/mobile/Ap ...

  6. pytest失败重跑

    一.说明 平常在做功能测试的时候,经常会遇到某个模块不稳定,偶然会出现一些bug,对于这种问题我们会针对此用例反复执行多次,最终复现出问题来.自动化运行用例时候,也会出现偶然的bug,可以针对单个用例 ...

  7. 项目开发中的git简单使用

    原文地址: https://www.zhuyilong.fun/tech/the-blog-git.html 示例远程仓库地址: https://github.com/zhu-longge/gitWo ...

  8. 痞子衡嵌入式:一次利用IAR自带CRC完整性校验功能的实践(为KBOOT加BCA)

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是利用IAR自带CRC完整性校验功能的一次实践(为KBOOT加BCA). 痞子衡之前写过两篇关于IAR中自带CRC校验功能的文章 < ...

  9. Mybatis【2.1】-- 从读取流到创建SqlSession发生了什么?

    目录 1.Resources.getResourceAsStream("mybatis.xml")到底做了什么? 2. new SqlSessionFactoryBuilder() ...

  10. 华为交换机eNSP删除Vlan的详细步骤

    设备支持批量删除VLAN和单个删除VLAN两种方式: 单个删除VLAN10 <HUAWEI> system-view [HUAWEI] undo vlan 10 批量删除VLAN10到VL ...