hdu4438 - Hunters

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值