bzoj2318 Spoj4060 game with probability problem

Source: Internet
Author: User

2318:spoj4060 game with probability problem time Limit: 1 Sec Memory Limit: MB
Submit: 259 Solved: 108
[Submit] [Status] [Discuss] Description

Aliceand theBobplaying a game. Have aNhere's a stone.Aliceand theBobToss the coin in turn, if the face is facing up, then fromNtake a stone out of a stone, or do nothing. The man who takes the last stone wins. Alicewhen throwing coins, there isPthe probability of throwing out the side he wanted to cast, likewise,Bobhave aQthe probability of throwing out his congenial side.

Now Alice throws a coin, assuming they all want to win the game and ask you What the probability of Alice winning is.

Input

The first line is a positive integer T, which represents the number of data groups.

For each set of data, a row of three numbers n,p,q.

Output

For each set of data output a single real number , which represents the probability of Alice winning, retains 6 decimal places.

Sample Input1

1 0.5 0.5


Sample Output0.666667


HINT

Data range:


1<=t<=50


0.5<=p,q<=0.99999999


For 100% of data 1<=n<=99999999




Game theory + probability DP

This problem I do not know very well, the direct handling of the problems (that I did not read):

http://blog.csdn.net/Vmurder/article/details/46467899

If someone understands, welcome to share with me, thank you.

There is a good idea: N is very large when growth for the answer is very small, so the N and 100 to the minimum, you can reduce the number of operations.




#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long longusing namespace Std;int t,n;double p,q,f[105],g[105];int main () {scanf ("%d", &t); f[0]=0;g[0]=1; while (t--) {scanf ("%d%lf%lf", &n,&p,&q); N=min (n,100); F (i,1,n) {if (f[i-1]>g[i-1]) p=1-p,q=1-q;f[i]= (p*g[i-1]+ (1-p) *q*f[i-1])/(n (1-p) * (1-Q)) g[i]= (q*f[i-1]+ (1-q) *p *G[I-1])/(1-p) * (1-Q); if (f[i-1]>g[i-1]) p=1-p,q=1-q;} printf ("%.6lf\n", F[n]);} return 0;}


bzoj2318 Spoj4060 game with probability problem

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.