Predictopus Problem

来源:互联网 发布:用mac硬盘怎么查看内容 编辑:程序博客网 时间:2024/05/22 03:39


Predictopus

Problem code: PREDICT

  • Submit
  • My Submissions
  • All Submissions

Chef Datta likes betting in Indian Premier League very much.

He has 10000 rupees. Today the match is between team A andteam B. The winning probability of team A is PA, and hence winning probability ofteam B is PB = 1 − PA.

Datta is free to bet any integral amount of money on any of the two teams as long as the total amount of money bet is at most10000 rupees.
Help him know the expected amount of money he will eventually have if today he places his bet(s) optimally.

Rules of the game:

If team X with winning probability PX actually wins and someone betsM rupees on this team, he will gain (2*(1−PX)) * M rupees.

If team X with winning probability PX actually loses and someone betsN rupees on this team, he will just lose N rupees.

Input

First line contains single integer T, the number of testcases. ThenT lines follow, each line contains PA the probability thatteam A wins.

Output

For each test case output single line containing the expected amount of money Datta will eventually have today if he places his bet(s) optimally. Your answer will be accepted if the absolute error is less than10−6.

Constraints

  • 1T100001 (105+1)
  • 0.0PA 1.0
  • PA has at most 5 digits after the decimal point.

Example

Input:10.510Output:10098

 

Example bet:

Look at the following situation:




june-codechef




If chef Datta bets 6,000 on team A and 4,000 onteam B, the expected amount of money he will have after the bet is settled is10,018. Apparently that is not the best he can do ;)

思路:这题只要将实例是怎么算出的就可以解决了,

设第一队胜出的几率 为p 投入m。 那么第二队的几率为1-p, 投入为10000 - m ,

那么第一队可以获得的钱为 (m * 2 *( 1 - p )  + m ) * p ;

同理可以得到第二队获得的钱为( (10000-m)*2*p + m ) *(1-p) ;

总的得钱数为(m * 2 *( 1 - p )  + m ) * p + ( (10000-m)*2*p + m ) *(1-p) 。化解即可求得

#include<iostream>#include<cmath>#include<cstdio>using namespace std ;int main(){    int t ;    scanf("%d",&t);    while(t--){        double px , py   , x  ;        scanf("%lf",&px);        py = 1-px ;        if(px>py)            x = 10000 ;        else            x = 0 ;       printf("%lf\n",(2*px + 1 )*py*10000 + (px-py) * x);    }    return 0;}


原创粉丝点击