Example 10-9 Duel UVa1636

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.