zoukankan      html  css  js  c++  java
  • 玩骰子(概率,暴力)

    暴力就行,不过要注意,如果一开始就赢了,那么就不用再置骰子了那么就为1了。

      1 #include<stdio.h>
      2 #include<stdlib.h>
      3 #include<algorithm>
      4 #include<iostream>
      5 #include<queue>
      6 #include<math.h>
      7 int kk();
      8 using namespace std;
      9 typedef long long ll;
     10 int a[7];
     11 int b[4];
     12 int c[4];
     13 int d[4];
     14 int main(void)
     15 {
     16     int n,i,j,k,p,q,s;
     17     scanf("%d",&k);
     18     while(k--)
     19     {
     20         for(i=1; i<=3; i++)
     21         {
     22             scanf("%d",&b[i]);
     23             c[i]=b[i];
     24         }
     25         for(i=1; i<=3; i++)
     26         {
     27             scanf("%d",&a[i]);
     28             d[i]=a[i];
     29         }
     30         int nn=kk();
     31         double sum;
     32         if(nn==1)
     33         {
     34             sum=1;
     35         }
     36         else
     37         {
     38             int uu=0;
     39             for(i=1; i<=3; i++)
     40             {
     41 
     42                 int rr=0;
     43                 for(s=1; s<=6; s++)
     44                 {
     45                     for(j=1; j<=3; j++)
     46                     {
     47                         c[j]=b[j];
     48                     }
     49                     c[i]=s;
     50                     rr+=kk();
     51                 }
     52                 if(rr>uu)
     53                 {
     54                     uu=rr;
     55                 }
     56 
     57             }
     58             sum=1.0*uu/6;
     59 
     60         }
     61         printf("%.3f
    ",sum);
     62     }
     63     return 0;
     64 
     65 }
     66 
     67 int kk()
     68 {
     69     int i,j,k,p,q;
     70     sort(c+1,c+4);
     71     sort(d+1,d+4);
     72     int cnt=0;
     73     int cnt2=0;
     74     for(i=2; i<=3; i++)
     75     {
     76         if(d[i]==d[i-1])
     77         {
     78             cnt++;
     79         }
     80         if(c[i]==c[i-1])
     81         {
     82             cnt2++;
     83         }
     84     }
     85     if(cnt2>cnt)
     86     {
     87         return 1;
     88     }
     89     else if(cnt2<cnt)
     90     {
     91         return 0;
     92     }
     93     else if(cnt==cnt2)
     94     {
     95         if(cnt==0)
     96         {
     97             int nx=d[1]+d[2]*10+d[3]*100;
     98             int ny=c[1]+c[2]*10+100*c[3];
     99             if(ny>nx)
    100             {
    101                 return 1;
    102             }
    103             else return 0;
    104         }
    105         if(cnt==1)
    106         {
    107 
    108             for(i=1; i<=3; i++)
    109             {
    110                 if(c[i]!=c[2])
    111                 {
    112                     break;
    113                 }
    114             }
    115             int nx=c[2]*100+c[2]*10+c[i];
    116             for(i=1; i<=3; i++)
    117             {
    118                 if(d[i]!=d[2])
    119                 {
    120                     break;
    121                 }
    122             }
    123             int ny=d[2]*100+d[2]*10+d[i];
    124             if(nx>ny)
    125             {
    126                 return 1;
    127             }
    128             else return 0;
    129         }
    130         else if(cnt==2)
    131         {
    132             if(c[1]>d[1])
    133             {
    134                 return 1;
    135             }
    136             else return 0;
    137         }
    138     }
    139 }
    油!油!you@
  • 相关阅读:
    查看Android应用所需权限(uses-permission)
    Android Camera后台拍照
    傅里叶变换
    linux文件系统问题:wrong fs type, bad option, bad superblock
    H3 android 系统编译
    开源股票数据工具
    获取股票实时交易数据的方法
    获取历史和实时股票数据接口
    CRC在线计算工具
    硬盘自动挂载
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/5009052.html
Copyright © 2011-2022 走看看