腾讯笔试,斗地主一个人拿到王炸的概率

#include<bits/stdc++.h>
using namespace std;
const int maxn=100;
int p[maxn],tot;

/*	
     抢地主的过程中尽量去凑成王炸,不过为啥影响不大 斗地主出王炸的概率,腾讯笔试题,这个竟然有人猜的到应该大于0.3 正确的概率差不多是33.5+,不过我没算出来,只能跑下随机数了 如果一个人手中有一个王,那么就给他凑成一个王炸 不过和直接拿到手的概率差不多,这很不科学 如果一副牌,在上次的基础上继续洗牌,这样概率就会降低到0.28左右 */ inline void solve(){ for(int i=1;i<=53;i++)swap(p[i],p[rand()%i]); int cnt[3]={0}; for(int i=0;i<51;i++)if(p[i]==52||p[i]==53)cnt[i%3]++; for(int i=51;i<54;i++)if(p[i]==52||p[i]==53){ for(int j=0;j<3;j++)cnt[i]++; } int rr=0; for(int i=0;i<3;i++){ if(cnt[i]==2)tot++,rr++; } if(rr==3)tot--; } int main(){ srand(time(NULL)); for(int i=1;i<=53;i++)p[i]=i; fstream out("out"); for(int cas=1;cas<=10000;cas++){ int mm=1e7;tot=0; double st=clock(); for(int i=0;i<mm;i++) solve(); printf("Case #%d: tot used time= %.6f %.6f ",cas,(clock()-st)/CLOCKS_PER_SEC,(double)tot/mm); out<<(clock()-st)/CLOCKS_PER_SEC<<tot<<endl; } return 0; }

  

原文地址:https://www.cnblogs.com/jihe/p/4534639.html