14年省赛k题

2019-04-14 15:45发布

class="markdown_views prism-atom-one-light">

K - Kick the ball!

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%

题意:

一场比赛中,a打一次球,b打一次球,五个轮回
若在比赛中出现了3 - 1 的情况的时候,若第四场a赢了,那么不用进行下一场了
给出每一次他们进球的概率,和一种比分 求:这一种比分出现的概率

处理:

当已经满足题目给的那一种比分并且不会变的时候
就返回这个概率,就是答案 #include #include #include #include using namespace std; const double eps=1e-8; char str[10]; double a[10]; double b[10]; int num1,num2; double deal(int pos,int SA,int SB,double p) { if(pos==10){ if(SA==num1&&SB==num2) return p; else return 0.0; } if(pos%2==0&&((abs(SA-SB))>(10-pos)/2)){ if(SA==num1&&SB==num2) return p; else return 0.0; } if(pos%2==1&&((SA-SB)>(10-pos)/2+1||(SB-SA)>(10-pos)/2)){ if(SA==num1&&SB==num2) return p; else return 0.0; } if(pos%2) return deal(pos+1,SA,SB+1,p*b[pos/2+1])+deal(pos+1,SA,SB,p*(1-b[pos/2+1])); return deal(pos+1,SA+1,SB,p*a[pos/2+1])+deal(pos+1,SA,SB,p*(1-a[pos/2+1])); } int main() { int cnt=1; // freopen("in.txt","r",stdin); while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&a[1],&a[2],&a[3],&a[4],&a[5],&b[1],&b[2],&b[3],&b[4],&b[5])!=EOF) { scanf("%s",str); num1=str[0]-'0',num2=str[2]-'0'; double ans=deal(0,0,0,1.0); printf("Case %d: %0.2lf%% ",cnt++,ans*100); } return 0; }