HDU 4043 Eliminate Witches! (求概率推公式 + 大数)
来源:互联网 发布:巴适公交暂无数据 编辑:程序博客网 时间:2024/05/16 09:00
FXTZ II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 525 Accepted Submission(s): 276
Total Submission(s): 525 Accepted Submission(s): 276
Problem Description
Cirno is playing a fighting game called "FXTZ" with Sanae.
Sanae is a ChuShou(master) of the game while Cirno is a ShaBao(noob). Since Cirno is a ShaBao, she just presses a random key on the keyboard for every 0.5 second, expecting to make a BiShaJi.
The battle begins. Having tried exactly 9 times, she finally makes a BiShaJi! She find herself summoned N iceballs!!! Then Sanae's HP decreases to 0 immediately....It should have been like that. But Cirno is too simple, always navie. She doesn't know how to handle the iceballs, so she starts to press the keyboard at random, again.
Let's see how the iceball damages. Each iceball has a fixed energy: the first ball's energy is 2^0, the second ball's energy is 2^1,..., and the N-th ball's energy is 2^(N-1). The damage caused by an iceball is equal to its energy. Cirno will shoot N times. Since Cirno is pressing the keyboard at random, each time Cirno will choose exactly one iceball with equal possibility to shoot out. Once shot out, the iceball can't be chosen again. And even worse, the target may be either her opponent or herself, with equal possibility(50%). What a big ShaBao she is. =_=
During shooting, once Cirno's HP is less than Sanae's, she will lose the game. Otherwise, she wins.
You may assume Sanae did nothing while Cirno's shooting(all damages are caused by Cirno's iceball), and their original HP are both 2^N (No one will die in the middle of the battle unless Cirno's HP is less than Sanae's).
Here comes the question: Can you calculate the possibility of Cirno's victory?
Sanae is a ChuShou(master) of the game while Cirno is a ShaBao(noob). Since Cirno is a ShaBao, she just presses a random key on the keyboard for every 0.5 second, expecting to make a BiShaJi.
The battle begins. Having tried exactly 9 times, she finally makes a BiShaJi! She find herself summoned N iceballs!!! Then Sanae's HP decreases to 0 immediately....It should have been like that. But Cirno is too simple, always navie. She doesn't know how to handle the iceballs, so she starts to press the keyboard at random, again.
Let's see how the iceball damages. Each iceball has a fixed energy: the first ball's energy is 2^0, the second ball's energy is 2^1,..., and the N-th ball's energy is 2^(N-1). The damage caused by an iceball is equal to its energy. Cirno will shoot N times. Since Cirno is pressing the keyboard at random, each time Cirno will choose exactly one iceball with equal possibility to shoot out. Once shot out, the iceball can't be chosen again. And even worse, the target may be either her opponent or herself, with equal possibility(50%). What a big ShaBao she is. =_=
During shooting, once Cirno's HP is less than Sanae's, she will lose the game. Otherwise, she wins.
You may assume Sanae did nothing while Cirno's shooting(all damages are caused by Cirno's iceball), and their original HP are both 2^N (No one will die in the middle of the battle unless Cirno's HP is less than Sanae's).
Here comes the question: Can you calculate the possibility of Cirno's victory?
Input
The first line an integer C (C<=30), the number of test cases.
For each case, the only line contains one integer N(0<N<=500), indicating the number of iceballs.
For each case, the only line contains one integer N(0<N<=500), indicating the number of iceballs.
Output
For each case output a fraction, the possibility of Cirno's victory. The fraction must be reduced.
Sample Input
214
Sample Output
1/235/128
Source
The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4043
题目大意:有两个人A,B玩游戏,A,B初始血量都为2^n,一共有n个球,第i个球的攻击力为2^(i - 1),A要选n个球攻击,每次随机选择一个攻击B,选择完该球就不能再用,攻击时有1/2概率攻击到自己,有1/2概率攻击到B,游戏过程中,一旦B的血量小于A,则A胜,当选完n个球A还是未胜则B胜,现在求B胜的概率
题目分析:考虑首项为1,公比为2的等比数列的第i项a[i] = s[i - 1] + 1,s[i]代表前i项和,所以我们考虑攻击力最大的那个球的位置,得到递推式:
pn = (1 / n) * (1 / 2) * (p1 + p2 + p3 +..+ pn-1),化简得到pn = 2n-1 / 2n * pn -1,因为n比较大,用大数做
题目大意:有两个人A,B玩游戏,A,B初始血量都为2^n,一共有n个球,第i个球的攻击力为2^(i - 1),A要选n个球攻击,每次随机选择一个攻击B,选择完该球就不能再用,攻击时有1/2概率攻击到自己,有1/2概率攻击到B,游戏过程中,一旦B的血量小于A,则A胜,当选完n个球A还是未胜则B胜,现在求B胜的概率
题目分析:考虑首项为1,公比为2的等比数列的第i项a[i] = s[i - 1] + 1,s[i]代表前i项和,所以我们考虑攻击力最大的那个球的位置,得到递推式:
pn = (1 / n) * (1 / 2) * (p1 + p2 + p3 +..+ pn-1),化简得到pn = 2n-1 / 2n * pn -1,因为n比较大,用大数做
import java.io.*;import java.math.*;import java.util.*;public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i = 0; i < t; i++) { BigInteger a = BigInteger.ONE; BigInteger b = BigInteger.valueOf(2); BigInteger n = in.nextBigInteger(); for(BigInteger j = BigInteger.valueOf(2); j.compareTo(n) <= 0; j = j.add(BigInteger.ONE)) { a = a.multiply(j.multiply(BigInteger.valueOf(2)).subtract(BigInteger.ONE)); b = b.multiply(j.multiply(BigInteger.valueOf(2))); BigInteger tmp = a.gcd(b); a = a.divide(tmp); b = b.divide(tmp); } System.out.println(a + "/" + b); } }}
0 0
- HDU 4043 Eliminate Witches! (求概率推公式 + 大数)
- hdu 4041 Eliminate Witches!
- HDU 4041 Eliminate Witches!
- HDU 4041 Eliminate Witches! --模拟
- hdu 4438 推公式求概率水题
- HDU 4041 Eliminate Witches! 树的遍历
- HDU 4041 Eliminate Witches! (栈的模拟)
- hdu 4041 Eliminate Witches! 栈和队列
- HDU 4041 Eliminate Witches!(模拟)
- hdu 4041 Eliminate Witches!(栈模拟)
- hdu 4041 Eliminate Witches! (栈的模拟)
- HDU-4041-Eliminate Witches! (11年北京网络赛!!)
- HDU ACM 4041 Eliminate Witches! 队列和栈模拟DFS
- [hdu4041]Eliminate Witches!
- UVA 11427 Expect the Expected (概率dp+推公式求期望 详解)
- HDU 4586 Play the dice(概率题,推公式)
- HDU 5245 Joyful 经典概率题目推公式
- HDu 4762 Cut the Cake 概率(推公式,积分)
- oracel 创建索引原则
- platform设备驱动全透析
- ARC机制
- 一种分布式框架设计(三)
- 为什么匿名内部类调用的方法内局部变量必须为final
- HDU 4043 Eliminate Witches! (求概率推公式 + 大数)
- 八皇后问题
- 南阳理工---题目1058部分和问题
- vim简单的实用总结
- windows server 2008r2 64位安装openssh
- 机器学习中导数最优化方法
- qnx常用命令
- Android--线程池实现方式解析
- 指针,和指针的引用