CSU 1513 Kick the ball! 点球大战(DFS)

题意:点球大战,轮流每队点射5个球,A先踢。如果当前比分已经能直接让比赛胜利接下来的球就不需要踢了。问最后的得分是题所给出的得分的概率


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
double a[6],b[6],ans;
int scord1,scord2;
void dfs(int rt,double p,int c1,int c2)
{
    int id=(rt+1)/2;  // 当前是哪个人踢。
    if(rt&1) {
        if((c1>c2+6-id) || (c2>c1+6-id)) {    // 如果比赛结束就提前终止    轮到A球员踢
            if(c1==scord1 && c2==scord2) ans+=p;
            return;
        }
    }
    else {                                      // 轮到B球员踢
        if((c1>c2+6-id) || (c2>c1+5-id)) {
            if(c1==scord1 && c2==scord2) ans+=p;
            return;
        }
    }
    if(rt&1) {
        if(c1<scord1) dfs(rt+1,p*a[id],c1+1,c2);
        dfs(rt+1,p*(1-a[id]),c1,c2);
    }
    else {
        if(c2<scord2) dfs(rt+1,p*b[id],c1,c2+1);
        dfs(rt+1,p*(1-b[id]),c1,c2);
    }
}
int main()
{
    int i,j,cc=0;
    while(scanf("%lf",&a[1])!=EOF) {
        for(i=2;i<=5;i++) scanf("%lf",&a[i]);
        for(i=1;i<=5;i++) scanf("%lf",&b[i]);
        scanf("%d-%d",&scord1,&scord2);
        ans=0;
        dfs(1,1,0,0);
        printf("Case %d: %.2lf%%\n",++cc,ans*100);
    }
    return 0;
}



"A penalty shoot-out (officially kicks from the penalty mark) is a method of determining the winner of an association football (soccer) match that is drawn after the regulation playing time and any applicable extra time periods have been played. In a penalty shoot-out, each team takes turns attempting a specified number of shots from the penalty mark (usually 5) that are only defended by the opposing team's goalkeeper, with the team scoring the most goals being declared the winner."
-- wikipedia
The game finally comes to the shoot-out. What will the final result be? "1-3!" You took a wild guess. But what is the probability that your guess is correct?
In this problem, team A kicks first (which is determined by a coin toss, as usual), both teams will attempt at most 5 shots (after all the 10 shots, the game may end in draw again), but the game will end as soon as the winner is already determined. For example, after the first 8 kicks the score is 3-2 (left side is team A’s score, right side is team B), then if the 9-th kick is a goal, the game will end immediately with score 4-2, because even team B got its last kick, it still loses for sure. Another example: if all the first 9 kicks are goals, the last kick (from team B) will still be performed, because although team B cannot win, the result might be a "draw", which is better than "lose".

Input

There will be at most 100 test cases. Each case contains two lines. The first line contains 10 floating numbers. The first 5 numbers are the goal probability of the players in team A (player 1 will shoot first, etc), the next 5 numbers are the goal probabilities of the players in team B. Each probability will have exactly one digit after the decimal point. The second line contains your guess, in the format of scoreA-scoreB. 0<=scoreA,scoreB<=5.

Output

For each test case, print the case number and the probability (in percentage) that your wild guess is correct, to 2 decimal places. An absolute error of 0.01% will be ignored.

Sample Input
0.4 0.7 0.7 0.6 0.5 0.8 0.9 0.7 0.2 0.8
1-3
1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0
2-0
1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0
2-0
0.4 0.7 0.7 0.6 0.5 0.8 0.9 0.7 0.2 0.8
5-5
0.4 0.7 0.7 0.6 0.5 0.8 0.9 0.7 0.2 0.8
4-2
Sample Output
Case 1: 6.98%
Case 2: 100.00%
Case 3: 0.00%
Case 4: 0.47%
Case 5: 9.73%

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【问题描述】在足球比赛中,有不少赛事,例如世界杯淘汰赛和欧洲冠军联赛淘汰赛中,当比赛双方经过正规比赛和加时赛之后仍然不分胜负时,需要进行点球大战来决定谁能够获得最终的胜利。点球大战的规则非常简单,两方轮流派出球员罚点球,每方各罚5个。当5轮点球结束以后如果仍然不分胜负,则进入一轮定胜负的阶段。两方各派一名球员罚点球,直到有一方罚进而另一方没有进为止。 在北美职业冰球联赛中,也有点球大战。与足球的规则不同的是,它只先罚3轮点球,随后就进入一轮定胜负的阶段,而其他的规则完全一样。 在本题中,输入将给出每次点球是否罚进,而你的任务则是输出一个“比分板”。 【输入形式】输入包含多组数据。每组数据的第一行包含一个整数N(1<=N<=18),表示双方总共罚了多少个点球,N=0表示输入结束。随后有N行,每行是一个如下形式的字符串: XXXX good:表示这个点球罚进 或者XXXX no good:表示这个点球没有罚进 其中XXXX表示球员名字(全部由字母和空格组成,保证不会出现歧义) 每一行保证不超过100个字符。 XXXX和good以及XXXX和no、no和good之间保证有且只有1个空格。 good、no good都是小写。本题是大小写相关的。 数据不保证点球大战一定结束,也不保证在结束以后立即结束这组数据(即:不用判断点球大战是否结束,只用把罚进的点球往比分上加即可)。 【输出形式】对每组数据,输出一个比分板。一个点球如果罚进,则在对应的地方标上’O’,如果没有进则标上’X’。先罚球的队伍的信息在上面,后罚的在下面。最右边标上两队的比分。具体格式参考样例输出。注意如果一轮点球只罚了一个,则后面那个点球对应的地方写上’-’。 【样例输入】 6 Riise good Ballack good Gerrard no good Lampard no good Fernando Torres good Malouda good 9 Christiano Ronaldo no good Messi no good Giggs good Abidal no good Carrick good Ronaldinho good Rooney good Henry no good Tevez good 0 【样例输出】 1 2 3 Score O X O 2 O X O 2 1 2 3 4 5 Score X O O O O 4 X X O X - 1

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值