Liang Guo Sha
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 527 Accepted Submission(s): 367
Problem Description
Maybe you know “San Guo Sha”, but I guess you didn’t hear the game: “Liang Guo Sha”!
Let me introduce this game to you. Unlike “San Guo Sha” with its complicated rules, “Liang Guo Sha” is a simple game, it consists only four cards, two cards named “Sha”, and the other named “Shan”.
Alice and Bob are good friends, and they’re playing “Liang Guo Sha” now. Everyone has two cards: a “Sha” and a “Shan”. Each round, everyone choose a card of his/her own, and show it together(Just show the selected card, do not
need to put it away). If both of them choose “Sha”, then Alice gets A points, and Bob loses A points; if both of them choose “Shan”, then Alice gets B points, and Bob
loses B points; otherwise, Bob gets C points, and Alice loses C points.
Both Alice and Bob wants to get points as many as possible, they thought a optimal strategy: Calculating a percentage of choosing card “Sha” in order to ensure that even the opponent uses the optimal strategy, he/she can still get a
highest point exceptation.
Here is the question, if both Alice and Bob use the optimal strategy to make their points higher, what is the expectation point which Alice can get in a round?
Input
Several test case, process to EOF.
Each test case has only a line, consists three positive integers: A, B, C respectively.
1 <= A, B, C <= 100000
Output
Each test case just need to output one line, the expectation point that Alice can get. Round to 6 decimal points.
Sample Input
Sample Output
0.200000
0.000000
Hint
In test case 1, both Alice and Bob calculated the best percentage of choosing “Sha”, and the their percentage are the same: 70%.
If Bob do not choose the best percentage, his strategy might be targetd.
For example, if Bob choose 100%, then Alice can change her percentage to 100%, Bob might lose many points. Bob is clever, so he won’t do that.
Source
题目大意:
If both of them choose “Sha”, then Alice gets A points, and
Bob loses A points; if both of them choose “Shan”, then Alice gets B points, and
Bob loses B points; otherwise, Bob gets C points, and
Alice loses C points.
给定A B C的值,求Alice得分的数学期望,已知Alice的数学期望与Bob无关。
解题思路:
假设Alice出杀的概率为pa,Bob出杀的概率为pb
则Alice得分的数学期望EX(Alice)=a*pa*pb+b*(1-pa)*(1-pb)-c*pa*(1-pb)-c*(1-pa)*pb;
整理得 EX(Alice)=pb*(a*pa+b*pa-b-c+2*c*pa)+b-b*pa-c*pa;
既然Alice的数学期望与Bob无关,那么pb的系数为0,则(a*pa+b*pa-b-c+2*c*pa)=0,
解得,pa=(b+c)/(a+2*c+b);
带入原方程求解得到答案
代码:
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
double a,b,c;
while(cin>>a>>b>>c){
double pa=(b+c)/(a+2*c+b);
double ans=b-b*pa-c*pa;
printf("%.6lf\n",ans);
}
return 0;
}
HDU 3910 Liang Guo Sha,布布扣,bubuko.com
HDU 3910 Liang Guo Sha
原文:http://blog.csdn.net/a1061747415/article/details/26284243