FXTZ II


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 498    Accepted Submission(s): 266

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?
 
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.
 
Output
For each case output a fraction, the possibility of Cirno's victory. The fraction must be reduced.
 
Sample Input
2
1
4
 
Sample Output
1/2
35/128
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  4049 4050 4044 4047 4042 
 

题目大意:

有n个能量球,能量分别为 2^0,2^1,2^2,........2^n-1

这个人每次随机选择一个能量球概率相同,选择后的可以看作消失了不能再被选,打中自己和敌人的概率都是50%,

过程中,一旦自己的血量小于对方就算输了,问自己赢的概率。

解题思路:

这题是分析概率题

首先,拿到题目,看到的输出样式是分子除以分母,这样的格式的话,不能只求概率,要用方法数来算

(1)可以确定的是为化简的分母,也就是总方法数,应该是 n 个雪球全排列后,然后再决定每个雪球打在谁身上。

也就是 n! * 2^n

(2)现在来分析分子,也就是赢的方法数

现在n个雪球排列好了在一排,

可以肯定的是第n个雪球是打在对方身上 ,否则我必输

因为第n个雪球的能量是2^(n-1) 大于剩下的 n-1 个球的能量总和

所以根据第n个球的位置讨论赢的方法数,假设这个球记为x,则其它球记为*

1.第n个雪球在1号位

x*****************

n-1 个雪球只需要随机排列(n-1)!,并且可以随便打谁2^(n-1) ,所以方法数为:c[n-1][0]*(n-1)!*2^(n-1)

2.第n个雪球在2号位

*x****************

只需要选择1个雪球在左边,n-2个雪球可以随便,所以方法数为:c[n-1][1]*(n-2)!*2^(n-2)

3.第n个雪球在3号位

**x***************

只需要选择2个雪球在左边,并且满足要求也就是dp[2],n-3个雪球可以随便,dp[2]*c[n-1][2]*(n-3)!*2^(n-3)

备注:dp[n]记录的是n个雪球时满足要求的方法数

4.第n个雪球在i号位

*******x**********

只需要选择i-1个雪球在左边,并且满足要求也就是dp[i-1],剩下的n-i个球随便放(n-i)!*2^(n-i)方法,所以方法数dp[i-1]*c[n-1][i-1]*(n-i)!*2^(n-i)

因此,总的赢的方法数dp[n] = sum { dp[i-1]*c[n-1][i-1]*(n-i)!*2^(n-i) } 1<=i<=n

化简:dp[n] = sum { dp[i-1] * (n-1)! * 2^(n-i) / (i-1)!  } 1<=i<=n

即  dp[n] = (n-1)! * ( dp[0]*2^(n-1)/0! + dp[1]*2^(n-2)/1!  + dp[2]*2^(n-3)/2! + ..... + dp[n-2]*2^1/(n-2)! + dp[n-1]*2^0/(n-1)! )

而dp[n-1] = (n-2)! * ( dp[0]*2^(n-2)/0! + dp[1]*2^(n-3)/1!  + dp[2]*2^(n-4)/2! + ..... + dp[n-2]*2^0/(n-2)! )

所以看出: dp[n]=(n-1)*2*dp[n-1]+dp[n-1]

所以  dp[n]=(2*n-1)*dp[n-1] ,dp[0]=1,

所以赢的方法数为:1*3*5*7*...*(2*n-1)

综合(1),(2)得到答案为1*3*5*7*...*(2*n-1) / (n! * 2^n)

解题代码:

import java.util.*;
import java.math.*; public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int T=scan.nextInt();
while(T-- >0){
int n=scan.nextInt();
BigInteger sum=new BigInteger("1"),x=new BigInteger("1");
for(int i=1;i<=n;i++){
sum=sum.multiply(BigInteger.valueOf(2*i));
x=x.multiply(BigInteger.valueOf(2*i-1));
}
BigInteger gcd0=x.gcd(sum);
System.out.println(x.divide(gcd0)+"/"+sum.divide(gcd0));
}
scan.close();
}
}

版权声明:欢迎关注我的博客,本文为博主toyking原创文章,未经博主允许不得转载。

HDU 4043 FXTZ II (组合数学-排列组合)的更多相关文章

  1. hdu 4043 FXTZ II [ 概率 + Java大数]

    传送门 FXTZ II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)

    Machine scheduling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. HDU 5816 状压DP&排列组合

    ---恢复内容开始--- Hearthstone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java ...

  4. HDU 1261 字串数(排列组合)

    字串数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  5. 【HDOJ】4043 FXTZ II

    1. 题目描述有n个球,第i个球的伤害值为$2^i-1, i \in [1,n]$.有甲乙两个人,每次由甲选择n个球中的一个,用它以相同概率攻击自己或者乙,同时彻底消耗这个球.这样的攻击最多进行n次. ...

  6. HDU 2492 BIT/逆序数/排列组合

    Ping pong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  7. ACM~排列组合&amp;&amp;hdu例子

    排列组合是数学中的一个分支.在计算机编程方面也有非常多的应用,主要有排列公式和组合公式.错排公式.母函数.Catalan Number(卡特兰数)等. 一.有关组合数学的公式 1.排列公式   P(n ...

  8. 排列组合+组合数取模 HDU 5894

    // 排列组合+组合数取模 HDU 5894 // 题意:n个座位不同,m个人去坐(人是一样的),每个人之间至少相隔k个座位问方案数 // 思路: // 定好m个人 相邻人之间k个座位 剩下就剩n-( ...

  9. HDU 4497 GCD and LCM(分解质因子+排列组合)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 题意:已知GCD(x, y, z) = G,LCM(x, y, z) = L.告诉你G.L,求满 ...

随机推荐

  1. Angular系列----AngularJS入门教程00:引导程序(转载)

    我们现在开始准备编写AngularJS应用——phonecat.这一步骤(步骤0),您将会熟悉重要的源代码文件,学习启动包含AngularJS种子项目的开发环境,并在浏览器端运行应用. 进入angul ...

  2. Spring基础——小的知识点

    一.整合多个配置文件 在 Spring Config 文件中,可以使用 <import> 标签将别的配置文件引入到一个文件中,进行配置文件的集成.该标签和 <bean> 标签同 ...

  3. Winform基础

    1.显示窗口的两种方式: 非模态(Modaless):Show 模态(Modal),阻塞主窗口:ShowDialog() 2.主窗口和对话框之间传递参数,在对话框中申明属性,主窗口给对话框传递值通过参 ...

  4. 计算几何 : 凸包学习笔记 --- Graham 扫描法

    凸包 (只针对二维平面内的凸包) 一.定义 简单的说,在一个二维平面内有n个点的集合S,现在要你选择一个点集C,C中的点构成一个凸多边形G,使得S集合的所有点要么在G内,要么在G上,并且保证这个凸多边 ...

  5. 消灭Bug!18款最佳的问题跟踪管理应用程序

    摘要:工欲善其事,必先利其器,对于开发者来说,处理Bug是一件比较头疼的事,那么如何高效地解决Bug,选择一款合适的Bug跟踪处理工具会让你事半功倍. 对于开发者来说,Bug往往是他们最头疼的问题.有 ...

  6. ActiveReports 9 新功能:可视化查询设计器(VQD)介绍

    在最新发布的ActiveReports 9报表控件中添加了多项新功能,以帮助你在更短的时间里创建外观绚丽.功能强大的报表系统,本文将重点介绍可视化数据查询设计器,无需手动编写任何SQL语句,主要内容如 ...

  7. PhpWind 8.7中禁止后台管理员随意修改会员用户名功能

    有人反映PHPWind 8.7中后台可以直接修改用户名的功能太过随意,干脆禁掉. OK,研究一下他的代码,admin/usermange.php  tempalate/admin/usermange. ...

  8. u-boot移植总结(四)u-boot-2010.09框架分析

    (一)本次移植是基于FL2440,板子的基本硬件: CPU 型号为S3C2440,基于ARM920T,指令集ARMV4,时钟主频400MHz SDRAM H57V2562GTR-75C 2片*32MB ...

  9. Java中处理异常throw和throws

    1.首先我们来了解什么是异常呢? 异常阻止当前方法或作用域继续执行的问题. 2.处理异常 说到处理异常,我们当然会想到 try catch finally 在java中我们会对异常的处理有更高的认识 ...

  10. 如何实现两个Activity 之间如何通讯

    <转> 今天主要学习了Activity 组件,在这里作一下总结 1,学习如何创建Activity 创建 Activity 要点: (1) 一个Activity就是一个类,并且这个类要继承A ...