例10-9 uva1636简单概率问题
2015-10-11 20:38
357 查看
题意:一个01串,0代表没子弹,1代表有子弹。在开一次空枪后,开下一枪没子弹概率大的方案
①接着开枪 ②随机转一下再开枪
思路:
在情况一就是求00在0中占的比例,情况二则是0在整个串中的比例
①接着开枪 ②随机转一下再开枪
思路:
在情况一就是求00在0中占的比例,情况二则是0在整个串中的比例
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib> #include <algorithm> typedef long long ll; using namespace std; const int maxn = 105; char p[maxn]; int main() { while(scanf("%s",p) != EOF) { int len =strlen(p); int anum = 0; int tnum; p[len] = p[0]; for(int i = 0; i < len; i++) { if(p[i] == '0') anum++; } double rotat = (double)anum / len; tnum = 0; for(int i = 0; i < len; i++) { if(p[i] == '0' && p[i+1] == '0') tnum ++; } double shoot = (double)tnum/anum; if(shoot > rotat) printf("SHOOT\n"); else if(shoot < rotat) printf("ROTATE\n"); else printf("EQUAL\n"); } return 0; }
相关文章推荐
- Linux使用dd命令备份大文件显示进度
- C++ 简单 Hash容器的实现
- poco c++和Boost库的对比分析
- 程序员面试之循环与递归(四)
- java产生缩略图
- ocp-302
- 一起talk C栗子吧(第五十六回:C语言实例--图的最短路径四)
- 背包问题1:01背包
- App快速上架经验
- 设计模式--里氏替换原则
- 信息安全系统设计基础第5周学习总结
- 音视频播放
- some commands for shutdown
- iframe有那些缺点
- 2015.10.10作业
- 全排列hash-康拓展开
- U-Boot启动过程完全分析
- 全排列hash-康拓展开
- 图像数据分块matlab
- 堆排序算法剖析(基于Java)