zoukankan      html  css  js  c++  java
  • Hunters

    Hunters

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 25   Accepted Submission(s) : 14
    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
     
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 int main()
     5 {
     6     int T,X,Y;
     7     double Q,P,tiger,wolf;
     8     scanf("%d",&T);
     9     while(T--)
    10     {
    11         getchar();
    12         scanf("%d%d%lf%lf",&X,&Y,&P,&Q);
    13         tiger=(1-Q)*X+Q*P*(X+Y);
    14         wolf=Q*Y+(1-Q)*P*(X+Y);
    15         if(tiger>wolf)
    16             printf("tiger %.4lf
    ",tiger);
    17         else
    18             printf("wolf %.4lf
    ",wolf);
    19     }
    20     return 0;
    21 
    22 }
    View Code
    转载请备注:
    **************************************
    * 作者: Wurq
    * 博客: https://www.cnblogs.com/Wurq/
    * Gitee: https://gitee.com/wurq
    **************************************
  • 相关阅读:
    【转载】HBase 数据库检索性能优化策略
    C语言结构
    c语言之sizeof总结
    C语言之Static
    转帖子:测试专家10年软件测试工作总结
    Word恢复文本转换器-修复损坏的WORD文件
    蓝桥杯 格子刷油漆
    小结博弈
    牛客寒假算法基础集训营6 E 海啸
    牛客寒假算法基础集训营4 F Applese 的大奖
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750281.html
Copyright © 2011-2022 走看看