题意:点球大战,轮流每队点射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".
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.
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.
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
Case 1: 6.98% Case 2: 100.00% Case 3: 0.00% Case 4: 0.47% Case 5: 9.73%