10个房间里放着随机数量的金币。每个房间只能进入一次,并只能在一个房间中拿金币。 一个人采取如下策略:前四个房间只看不拿。随后的房间只要看到比前四个房间都多的金币数, 就拿。否则就拿最后一个房间的金币
2016-03-21 18:05
423 查看
#include<iostream> #include<math.h> #include <time.h> using namespace std; int num[10]; inline void SrandNum() { num[0]=rand()%100000; num[1]=rand()%100000; num[2]=rand()%100000; num[3]=rand()%100000; num[4]=rand()%100000; num[5]=rand()%100000; num[6]=rand()%100000; num[7]=rand()%100000; num[8]=rand()%100000; num[9]=rand()%100000; } int MaxNum() { int Max=-1; for(int i=0;i<10;i++) { if(num[i]>=Max) Max=num[i]; } return Max; } int AfterMax() { int Max=-1; for(int i=0;i<4;i++) if(num[i]>=Max) Max=num[i]; for(int i=4;i<9;i++) if(num[i]>Max) return num[i]; return num[9]; } int main() { srand((unsigned) time(NULL)); int times=0; int total=0; int max=-1; int afternum=-1; while(times<1000000) { SrandNum(); max=MaxNum(); afternum=AfterMax(); if(afternum==max) total++; times++; } cout<<total<<endl; return 0; }数值维持在39.8%左右。
相关文章推荐
- 竞赛系统需求分析
- CSS总结(七)——常见的两栏、三栏布局
- jQuery 序列化表单数据 serialize() serializeArray()
- Codeforces 653D Delivery Bears【二分+网络流】
- 测试知识
- 优化Android App性能 -邱公占
- 第二部分:浅析 Linux 初始化 init 系统:upstart
- android获取recycleview滚动的距离
- 浏览器与服务器的消息通信
- Codeforces 653D Delivery Bears【二分+网络流】
- 几种算法的总结
- lists删除
- 浏览器与服务器的消息通信
- SOAP UI
- HBase特征
- spring-beanFactory
- composer遇到Your configuration does not allow connection to http://的问题怎么解决
- acm 1004 节目-时间
- android -- 蓝牙 bluetooth (三)搜索蓝牙
- 读写锁rwlock