浙江工业大学校赛 XiaoWei的战斗力

XiaoWei的战斗力

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 536    Accepted Submission(s): 122


Problem Description
XiaoWei沉迷RPG无法自拔,但是他的战斗力只有5,所以他决定氪金提升战斗力。
XiaoWei购买了n个福袋。打开1个福袋后,有以下三种情况出现:
1.获得屠龙宝刀,概率为p1;
2.获得火麒麟,概率为p2;
3.什么都没获得,概率为1-p1-p2;
已知每把屠龙宝刀能够使战斗力*2,每把火麒麟能够使战斗力*1.5。XiaoWei虽然初始战斗力很弱,但是潜力无限,可以装备任意数量的屠龙宝刀和火麒麟,并且效果可以叠加。XiaoWei想知道,打开n个福袋后并装备武器后,他的战斗力期望是多少?
 

Input
第一行只包含一个整数T(1≤T≤100),表示有T组数据。
对于每组数据,包含1个整数n(1≤n≤20),和2个浮点数p1和p2(0≤p1,p2≤1 且 0≤p1+p2≤1)。
 

Output
对于每组数据,输出一行结果。
输出格式为“Case #x: y”,x表示数据组数(从1开始),y表示答案。
y以科学计数法输出,保留三位有效数字。
 

Sample Input
3 1 0.5 0.5 2 1 0 20 0 0
 

Sample Output
Case #1: 8.75e+000 Case #2: 2.00e+001 Case #3: 5.00e+000
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long int ll;

struct face{
    int num;
    double ans;
}f[1005];
bool cmp(face a,face b){
    return a.ans<b.ans;
}
int main(){
    int t;
    int ca=1;
    while(~scanf("%d",&t)){
        int n;
        while(t--){
            scanf("%d",&n);
            double p1,p2;
            scanf("%lf %lf",&p1,&p2);
            double p=1+p1+0.5*p2;
            double ans=5;
            ans=ans*pow(p,1.0*n);
            printf("Case #%d: ",ca++);
            printf("%.2e
",ans);
        }
    }
    return 0;
}



 

原文地址:https://www.cnblogs.com/dacc123/p/8228533.html