HDU-4438-Hunters

Hunters

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1107    Accepted Submission(s): 850

Problem Description

Alice and Bob are the topmost hunters in the forest, so no preys can escape from them. However, they both think that its hunting skill is better than the other. So they need a match.

In their match, the targets are two animals, a tiger and a wolf. They both know that the tiger is living in the south of the forest and the wolf is living in the north of the forest. They decide that the one who kills the tiger scores X points and who kills
the wolf scores Y points. If the one who kills both tiger and wolf scores X+Y points.

Before the match starts, Alice is in the east of the forest and Bob is in the west of the forest. When the match starts, Alice and Bob will choose one of the preys as targets. Because they haven‘t known the other‘s choice, maybe they choose the same target.
There will be two situations:

(1) If they choose different targets, they both are sure of killing their respective targets.

(2) If they choose the same target, the probability of Alice killing the target is P, and the probability of Bob killing it is 1-P. Then they will hunt for the other prey, also the probability of Alice killing it is P and the probability of Bob killing it is
1-P.

But Alice knows about Bob. She knows that the probability of Bob choosing tiger as his first target is Q, and the probability of choosing wolf is 1-Q. So that Alice can decide her first target to make her expected score as high as possible.

Input

The first line of input contains an integer T (1≤T≤10000), the number of test cases.

Then T test cases follow. Each test case contains X, Y, P, Q in one line. X and Y are integers and 1≤X, Y≤1000000000. P and Q are decimals and 0≤P, Q≤1, and there are at most two digits after decimal point.

Output

For each test case, output the target Alice should choose and the highest expected score she can get, in one line, separated by a space. The expected score should be rounded to the fourth digit after decimal point. It is guaranteed that Alice will have different
expected score between choosing tiger and wolf.

Sample Input

3
2 1 0.5 0.5
2 1 0 1
7 7 0.32 0.16

Sample Output

tiger 1.7500
wolf 1.0000
tiger 6.5968

Source

2012 Asia Tianjin Regional Contest

绝对水题!!

就是两个期望值!!

不过陷在浮点数陷阱里错了一次!!

以后注意浮点数不能直接相等!!

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int T;
	double x, y, p, q;
	scanf("%d", &T);
	while(T--)
	{
		scanf("%lf %lf %lf %lf", &x, &y, &p, &q);
		double ans1 = q*(x*p+y*p) + (1-q)*x, ans2 = (1-q)*(x*p+y*p) + q*y;
		if(ans1 > ans2)printf("tiger %.4lf\n", ans1);
		else printf("wolf %.4lf\n", ans2);
	}
	return 0;
} 

AC代码(之前没注意浮点数陷阱错了一次):

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define max(a,b) (a)>(b)?(a):(b)
using namespace std;

int main()
{
    int T, x, y;
    double p, q;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d %d %lf %lf", &x, &y, &p, &q);
        double ans1=q*(x*p+y*p) + (1-q)*x, ans2=(1-q)*(x*p+y*p) + q*y;
        double ans = max(ans1, ans2);
        if(ans-ans1<1e-6)printf("tiger ");  //不能写ans==ans1,会产生浮点数误差!!
        else printf("wolf ");
        printf("%.4lf\n", ans);
    }
    return 0;
} 
时间: 2024-10-10 20:39:50

HDU-4438-Hunters的相关文章

HDU 4438 Hunters (数学,概率计算)

题意:猎人A和B要进行一场比赛.现在有两个猎物老虎和狼,打死老虎可以得X分,打死狼可以得Y分.现在有两种情况: (1)如果A与B的预定目标不同,那么他们都将猎到预定的目标. (2)如果A与B的预定目标相同,A杀死目标的概率为P,B杀死这个目标的概率为1-P.接着他们将猎取第二只猎物,概率同上. 现在A知道B选择老虎作为他的首目标的概率为Q,B选狼作为首目标的概率为1-Q.所以A必须选择他的首目标,来使得他的期望分数最高. 析:分情况讨论么,首先选Tiger,再选Wolf,看看哪个大,就选哪个,比

HDU 4438 Hunters 区域赛水题

本文转载于 http://blog.csdn.net/major_zhang/article/details/52197538 2012天津区域赛最水之题: 题意容易读懂,然后就是分情况求出A得分的数学期望,所谓数学期望就是在该概率下的平均得分. 现在就是两种方案,Alice要根据输入给出的数据情况选出最优方案,也就是先选老虎,还是狼. 1.A先选老虎: a.B也先选老虎,则得分为Q(P*X+P*Y); //打完老虎还要打狼 b.B选狼,则两人可以直接获得猎物,则得分为(1-Q)*X 所以1方案

hdu 4438

比较水的概率题:写出公式即可 #include <iostream> #include <stdio.h> #include <string> #include <string.h> #include <algorithm> using namespace std; int main() { int T; scanf("%d",&T); while(T--) { double x,y,p,q; scanf("

hdu 4438 第37届ACM/ICPC 天津赛区现场赛H题

题意:Alice和Bob两个人去打猎,有两种(只)猎物老虎和狼: 杀死老虎得分x,狼得分y: 如果两个人都选择同样的猎物,则Alice得分的概率是p,则Bob得分的概率是(1-p): 但是Alice事先知道Bob先选老虎的概率是Q,问Alice得分的期望最大值是 求期望 如果先去打老虎,则会有bob先去打狼和bob去打老虎两种情况,期望相加则是alice去打老虎的期望,然后求打狼的期望,比较大小即可 1 #include<cstdio> 2 #include<iostream> 3

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;

HDU 5542 The Battle of Chibi dp+树状数组

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:给你n个数,求其中上升子序列长度为m的个数 可以考虑用dp[i][j]表示以a[i]结尾的长度为j的上升子序列有多少 裸的dp是o(n2m) 所以需要优化 我们可以发现dp的第3维是找比它小的数,那么就可以用树状数组来找 这样就可以降低复杂度 #include<iostream> #include<cstdio> #include<cstring> #include

hdu 1207 汉诺塔II (DP+递推)

汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4529    Accepted Submission(s): 2231 Problem Description 经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往

[hdu 2102]bfs+注意INF

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 感觉这个题非常水,结果一直WA,最后发现居然是0x3f3f3f3f不够大导致的--把INF改成INF+INF就过了. #include<bits/stdc++.h> using namespace std; bool vis[2][15][15]; char s[2][15][15]; const int INF=0x3f3f3f3f; const int fx[]={0,0,1,-1};

HDU 3555 Bomb (数位DP)

数位dp,主要用来解决统计满足某类特殊关系或有某些特点的区间内的数的个数,它是按位来进行计数统计的,可以保存子状态,速度较快.数位dp做多了后,套路基本上都差不多,关键把要保存的状态给抽象出来,保存下来. 简介: 顾名思义,所谓的数位DP就是按照数字的个,十,百,千--位数进行的DP.数位DP的题目有着非常明显的性质: 询问[l,r]的区间内,有多少的数字满足某个性质 做法根据前缀和的思想,求出[0,l-1]和[0,r]中满足性质的数的个数,然后相减即可. 算法核心: 关于数位DP,貌似写法还是

HDU 5917 Instability ramsey定理

http://acm.hdu.edu.cn/showproblem.php?pid=5917 即世界上任意6个人中,总有3个人相互认识,或互相皆不认识. 所以子集 >= 6的一定是合法的. 然后总的子集数目是2^n,减去不合法的,暴力枚举即可. 选了1个肯定不合法,2个也是,3个的话C(n, 3)枚举判断,C(n, 4), C(n, 5) #include <bits/stdc++.h> #define IOS ios::sync_with_stdio(false) using name