CSU 1513 Kick the ball!

DFS

题目的意思为 告诉你每个人进球概率的情况下 以当前比分结束这场比赛的概率是多少

 数据量很小 直接枚举所有情况

注意下判断比赛结束时的条件 如果比赛已经结束但是分数未达到要求时 要停止搜索(坑)

当比赛已经结束且分数达到要求时 将当前状态的概率加上

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
double a[7],b[7];
int x,y;
double ans;
void dfs(int h,int c,int nh,int nc,double s,bool flag)
{
    if(((6-nh)+h<c||(6-nc)+c<h)&&(x!=h||y!=c))
        return;
    if(x==h&&y==c&&((6-nh)+h<c||(6-nc)+c<h))
    {
        ans+=s;
        return;
    }
    if(nh==6&&nc==6)
    {
        if(h==c&&h==x&&c==y)
            ans+=s;
        return;
    }
    if(flag==0)
    {
        dfs(h+1,c,nh+1,nc,s*a[nh],1);
        dfs(h,c,nh+1,nc,s*(1-a[nh]),1);
    }
    else
    {
        dfs(h,c+1,nh,nc+1,s*b[nc],0);
        dfs(h,c,nh,nc+1,s*(1-b[nc]),0);
    }
}
int main()
{
    int o=1;
    while(~scanf("%lf",&a[1]))
    {
        int i,j,k,l;
        for(i=2;i<=5;i++)
            scanf("%lf",&a[i]);
        for(j=1;j<=5;j++)
            scanf("%lf",&b[j]);
        scanf("%d-%d",&x,&y);
        ans=0;
        dfs(0,0,1,1,1,0);//6个参数分别表示 a队得分 b队得分 a队当前踢球球员 b队当前踢球球员 当前状态概率 当前应当哪队踢
        printf("Case %d: %.2lf",o++,ans*100);
        cout<<"%"<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值