CSU 1513 Kick the ball!

来源:互联网 发布:网络虚拟物品交易平台 编辑:程序博客网 时间:2024/04/29 09:36

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
原创粉丝点击