HDU 3910 Liang Guo Sha

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

2 10 4
3 3 3

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

2011 Multi-University Training
Contest 8 - Host by HUST

题目大意:

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

时间: 2024-10-27 19:07:03

HDU 3910 Liang Guo Sha的相关文章

hdu 4739Zhuge Liang&#39;s Mines(简单dfs,需要注意重点)

Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1166    Accepted Submission(s): 505 Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous

HDU3910(数学期望题,题目难懂)

Liang Guo Sha Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 590    Accepted Submission(s): 426 Problem Description Maybe you know “San Guo Sha”, but I guess you didn’t hear the game: “Liang Gu

C#字符操作

//字符串转ASCII码 // str1:字符串 str2:ASCII码 if (Encoding.GetEncoding("unicode").GetBytes(new char[] { str1[0] })[1] == 0)//判断输入是否为字母 { str2= Encoding.GetEncoding("unicode").GetBytes str1[0].ToString();//得到字符的ASCII码值 } //ASCII码转字符 int P_int_Nu

帮助类下

#region HTML代码转换成TXT格式 1010 /// <summary> 1011 /// 字符串字符处理 1012 /// </summary> 1013 /// <param name="chr">等待处理的字符串</param> 1014 /// <returns>处理后的字符串</returns> 1015 /// //把HTML代码转换成TXT格式 1016 public static Stri

汉字转拼音 完整类

using System;using System.Collections.Generic;using System.Text; namespace WindowsApplication1{    public static class ChineseToPinYin    {/// <summary>        /// 汉字拼音转换类        /// </summary>        public class PinYinConverter        {     

关于C# 汉字转拼音问题

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace MyPinYin 7 { 8 /// <summary> 9 /// 汉字拼音转换类 10 /// </summary> 11 public class PinYinConverter 12 { 13 #region 数组信息 14 15 private static

C# 汉字转拼音(支持GB2312字符集中所有汉字)

GB2312标准共收录6763个汉字,其中一级汉字3755个,二级汉字3008个. 分区表示  GB 2312中对所收汉字进行了“分区”处理,每区含有94个汉字/符号.这种表示方式也称为区位码. 1)01-09区为特殊符号. 2)16-55区为一级汉字,按拼音排序.  3)56-87区为二级汉字,按部首/笔画排序. 4)10-15区及88-94区则未有编码. 也就是说二级汉字与拼音不存在联系.这样网上大部分汉字转拼音类只能正确获取部分汉字的拼音(一级汉字).只有小数的3000多一点汉字.  而二

完整的系统帮助类Utils

//来源:http://www.cnblogs.com/yuangang/p/5477324.html using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Net; using System.Web; using System.Security.Cryptography; using System.Text.Regul

汉字拼音转换类

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyPinYin { /// /// 汉字拼音转换类 /// public static class PinYinConverter { #region 数组信息 private static int[] pyValue = new int[] { -20319, -20317, -20304, -2029