1. Title Description: Click to open the link
2. Problem-solving ideas: According to test instructions know: directly in key a gun is equivalent to two times are 00 sequence, a random turn and then pull the equivalent is exactly meet 0, so it is not difficult to calculate the probability of both. The former is a conditional probability, equal to 00 of the number divided by the number of 00+01, the latter is the ratio of 0. Set 00 Sequence number is a (note that the bullets are annular, the end is equivalent to continuous), 0 of the number is B, the length of the string is N, then the two probabilities are a/b,b/n. So the final comparison between the size of A*n and b*b can be.
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace Std;int main () {freopen ("test.txt", "R", stdin); string S;while (cin >> s) {int a=0, b=0, n;n = S.length (); for (int i = 0; i < n;i++) if (s[i] = = ' 0 ') b++;for (int i = 0; i < n;i++) if (s[i] = = ' 0 ' && s[(i + 1)%n] = = ' 0 ') a++;if (a*n>b*b) printf ("shoot\n"); else if (a*n = = b*b) printf ("equal\n"), Else printf ("rotate\n");} return 0;}
Example 10-9 Duel UVa1636