http://acm.hdu.edu.cn/showproblem.php?pid=4438
分情况讨论:
A:表示Alice打tiger时 :
a、Bob打tiger的概率为q , 那么得分为 q * (1 - p ) * p * x + q * p * p * x + q * ( 1 - p ) * p * y + q * p * p* y ; ;
b、Bpb打wolf的概率为 1 - q , 那么得分为 ( 1 - q ) * y;
B:表示Alice打wolf时:
a、Bob打tiger的概率为q , 那么得分为 q * x ;
b、Bpb打wolf的概率为 1 - q , 那么得分为 ( 1 - q ) * p *( 1 - p ) x+ ( 1 -q ) * p * p * x + ( 1 - q ) * p * ( 1 - p ) * y; + ( 1 - q ) * p * p * y ;
以上求概率就是分了三种情况,就是打中其中一只有两种 ,两只都打中的一种情况,具体的参照公式好好理解即可
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "math.h"
#include "algorithm"
#include "iostream"
using namespace std;
#define esp 1e-6
int main()
{
int x , y , i , j , n ;
double p , q ;
while( ~scanf( "%d" ,&n ) )
{
while( n-- )
{
scanf( "%d%d%lf%lf" , &x , &y , &p , &q ) ;
double ans1 = ( 1.0 - q ) * x + 1.0 * q * ( p * x + p * y ) ;
double ans2 = 1.0 * q * y + 1.0 * ( 1.0 - q ) * ( p * x + p * y ) ;
if( ans1 - ans2 >= esp )
printf( "tiger %.4lf\n" , ans1 );
else
printf( "wolf %.4lf\n" , ans2 );
}
}
return 0;
}