UVA 1636 Head Shot 概率 数学
题目链接: https://vjudge.net/problem/UVA-1636
题目描述: 一个左轮手枪有空弹还有实弹, 有两种操作, 直接抠下一发或者随机转一下, 给出你左轮手枪的子弹序列, 让你求一直第一发是空弹的情况下, 下一发哪种操作时空弹的可能性大
解题思路: 很基础的概率题, 只要分别求两个的概率即可
代码:
#include <iostream> #include <cstdio> #include <string> #include <vector> #include <cstring> #include <iterator> #include <cmath> #include <algorithm> #include <stack> #include <deque> #include <map> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define mem0(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,-0x3f,sizeof(a)) #define fi(n) for(i=0;i<n;i++) #define fj(m) for(j=0;j<m;j++) #define sca(x) scanf("%d",&x) #define ssca(x) scanf("%s",x) #define scalld(x) scanf("%I64d",&x) #define print(x) printf("%d\n", x) #define printlld(x) printf("%I64d\n",x) #define de printf("=======\n") #define yes printf("YES\n") #define no printf("NO\n") typedef long long ll; using namespace std; const int eps = 1e-9; const int maxn = 150; char a[maxn]; int main() { while( ssca(a) != EOF ) { int len = (int)strlen(a); int n = 0; for( int i = 0; i < len; i++ ) { if( a[i] == '0' ) n++; } double ran = double(n)/double(len); int sum = 0; for( int i = 0; i < len; i++ ) { if( a[i] == '0' ) { if( a[(i+1)%len] == '0' ) { sum++; } } } double sho = double(sum)/double(n); if( ran - sho > eps ) { printf( "ROTATE\n" ); } else if( sho > ran > eps ) { printf( "SHOOT\n" ); } else { printf( "EQUAL\n" ); } } return 0; }
思考: 对条件概率的理解要加深
}
posted on 2017-08-23 10:57 FriskyPuppy 阅读(249) 评论(0) 编辑 收藏 举报