HDU 4043 Eliminate witches! (Calculate probability formula + large number)

Source: Internet
Author: User


Fxtz IITime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
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 has been like that. But Cirno was too simple and always navie. She doesn ' t know how to handle the iceballs, so she starts-press the keyboard at random, again.
Let's see how the Iceball damages. Each iceball have a fixed energy:the first ball's energy are 2^0, the second ball's energy are 2^1,..., and the n-th ball ' s Energy is 2^ (N-1). The damage caused by an iceball are equal to their energy. Cirno'll shoot N times. Since Cirno is pressing the keyboard at random, each time Cirno would 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 she opponent or herself, with equal possibility (50%). What's a big shabao she is. =_=
During shooting, once Cirno ' s HP is less than Sanae ' s, she'll lose the game. Otherwise, she wins.
You may assume Sanae do nothing while Cirno's shooting (all damages is caused by Cirno ' s iceball), and their original HP is both 2^n (No one would 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?
 
InputThe first line an integer C (c<=30), the number of test cases.
The only line contains one integer N (0<n<=500), indicating the number of iceballs.
 
Outputfor each case output a fraction, the possibility of Cirno ' s victory. The fraction must be reduced.
 
Sample Input
214
 
Sample Output
1/235/128
 
SourceThe 36th ACM/ICPC Asia Regional Beijing site--online Contest 
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4043

The main topic: There are two people, a, B play games, A, a, a, b initial blood volume is 2^n, a total of N ball, the first ball of the attack is 2^ (i-1), A to choose N ball attack, each time randomly select an attack, select the ball can no longer use, attack with 1/2 probability attack to oneself, there is 1/2 probability , in the course of the game, once the blood amount of B is less than a, then a wins, after the election of N ball A or not win B wins, now the probability of B wins

Title Analysis: Consider the first item for 1, the geometric series of 2 for the a[i] = S[i-1] + 1,s[i] for the first and so we consider the position of the most attacking ball, get the recursive type:
PN = (1/n) * (*) * (p1 + p2 + p3 +). + pn-1), simplify to get PN = 2n-1/2n * pn-1, because n is larger, do it in large numbers


Import java.io.*;import java.math.*;import java.util.*;p ublic class Main {public    static void Main (string[] args) { C1/>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);}}}    

HDU 4043 Eliminate witches! (Calculate probability formula + large number)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.