• csu 1513 Kick the ball! 搜索


     题意:

    点球大战 双方各有五名队员

    一队一人交替点球

    如果中途已经决出胜负了 那就不用继续了

    问最后踢成x-y这种比分的可能性 

    思路:

    直接搜索 注意跳出条件

    训练时没有A出来就是因为跳出条件

    aa bb是A B两队当前主罚队员

    如果到了5 就意味着这一队已经结束了点球

    一开始写成了到4结束 就相当于最后一个人没有踢……

     1 #include<bits/stdc++.h>
     2 #define cl(a,b) memset(a,b,sizeof(a))
     3 #define debug(x) cerr<<#x<<"=="<<(x)<<endl
     4 using namespace std;
     5 
     6 int x,y;
     7 double a[5],b[5],ans;
     8 
     9 
    10 // A:B   当前比分
    11 // turn  哪一方踢
    12 // aa bb 当前双方主罚队员
    13 // res   当前状态概率
    14 
    15 void dfs(int A,int B,bool turn,int aa,int bb,double res)
    16 {
    17     //到4代表是最后一个人罚球 到5才是结束了 超过5都是多搜的
    18     if(aa>5||bb>5) return ;
    19     if(5-aa+A<B||5-bb+B<A)
    20     {//一方必胜 结束点球大战
    21         if(A==x&&B==y)
    22         {
    23             ans+=res;
    24         }
    25         return ;
    26     }
    27     if(A==x&&B==y&&aa==5&&bb==5)
    28     {//已经达成目标分数并且双方球员点球结束
    29         ans+=res;
    30         return ;
    31     }
    32     if(turn)
    33     {//A队主罚点球
    34         //进了
    35         dfs(A+1,B,!turn,aa+1,bb,res*a[aa]);
    36         //没进
    37         dfs(A+0,B,!turn,aa+1,bb,res*(1.0-a[aa]));
    38     }
    39     else
    40     {//B队主罚点球
    41         //进了
    42         dfs(A,B+1,!turn,aa,bb+1,res*b[bb]);
    43         //没进
    44         dfs(A,B+0,!turn,aa,bb+1,res*(1.0-b[bb]));
    45     }
    46 }
    47 
    48 int main()
    49 {
    50     int cas=1;
    51 //    freopen("in.txt","r",stdin);
    52     while(~scanf("%lf",&a[0]))
    53     {
    54         for(int i=1;i<5;i++)
    55         {
    56             scanf("%lf",&a[i]);
    57         }
    58         for(int i=0;i<5;i++)
    59         {
    60             scanf("%lf",&b[i]);
    61         }
    62         ans=0.0;
    63         scanf("%d-%d",&x,&y);
    64         dfs(0,0,true,0,0,1.0);
    65         printf("Case %d: %.2f%%
    ",cas++,ans*100);
    66     }
    67     return 0;
    68 }/*
    69 
    70 0.4 0.7 0.7 0.6 0.5 0.8 0.9 0.7 0.2 0.8
    71 1-3
    72 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0
    73 2-0
    74 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0
    75 2-0
    76 0.4 0.7 0.7 0.6 0.5 0.8 0.9 0.7 0.2 0.8
    77 5-5
    78 0.4 0.7 0.7 0.6 0.5 0.8 0.9 0.7 0.2 0.8
    79 4-2
    80 
    81 */
  • 相关阅读:
    spark SQL之 DataFrame和DataSet
    scala之 保留小数
    spark之 避免数据倾斜之 给名字分区(百家姓)
    hive之 'client_protocol' is unset!
    hive之报错:ls:cannot access '/usr/local/spark/lib/spark-assembly-*.jar':No such file or directory
    hive之 Error: Duplicate key name 'PCS_STATS_IDX' (state=42000,code=1061) ----Hive schematool -initSchema
    Maven中需要注意的点
    spark之 Idea操作
    scala之 一句话打印三角形
    scala 之 BaseDao
  • 原文地址:https://www.cnblogs.com/general10/p/6816962.html
Copyright © 2020-2023  润新知