Ball playing game (a ^ B game)

Source: Internet
Author: User

Problem 3 ball. cpp/c/pas [Title Description] Stas and Masha invented a game. Game items are a different box and B different balls. Stas and Masha take turns, and each operation adds a completely different box or ball. If, after Stas or Masha operations, the number of solutions to put B balls in a box is no less than n, then this person will lose. All boxes and balls are different. You can leave empty boxes. If the first round is first played by Stas, and both Stas and Masha are playing the game according to the optimal policy, will the game be flattened? Who will lose if it is not flat ?? [Input format] the first line of the input contains three positive integers a, B, and n. [Output format] If Stas is input, 'stas' is output (do not output quotation marks); If Masha is input, 'masha' is output; if the game is flattened (that is, it is not ended ), output 'missing '. [Example input] Example 1: 2 2 10 Example 2: 5 5 16808 Example 3: 3 1 4 example 4: 1 4 10 [sample output] Example 1: Masha Example 2: Masha Example 3: Stas Example 4: Missing [data range] for 10% of data, n cannot exceed 10; n cannot exceed 30% of data. For 100% of data, 1 ≤ a ≤ 10,000, 1 ≤ B ≤ 30, 2 ≤ n ≤ 1,000,000,000, a ^ B In the game, a ^ B = n indicates the memory of the situation used by a> 1 (with few cases). The only draw case is a = 1 B = x (a + 1) ^ B explosion another kind is that 1 ^ x 2 ^ x explosion judge parity can actually pass through (sweat-_-) without memory -_-). [Cpp] # include # Include # Include# Include # Include # Include # Include Using namespace std; # define MAXN (1000000000) # define MAXA (10000 + 10) # define MAXB (30 + 10) long a, B, n; bool pow2 (long a, long B) {long ans = 1; for (int I = 1; I <= B; I ++) {ans * =; if (ans> = n) return 0;} return 1;} int dfs (long a, long B) //, status B is valid. 0 Miss 1 Win-1 Lost {if (a = 1 &&! Pow2 (a + 1, B) return 0; int flag =-1; if (a = 1) {if (pow2 (a + 1, B )) flag = max (-dfs (a + 1, B), flag); if (flag = 1) return 1; if (pow2 (a, B + 1 )) flag = max (-dfs (a, B + 1), flag); return flag;} else {if (pow2 (a, B + 1 )) flag = max (-dfs (a, B + 1), flag); if (flag = 1) return 1; if (pow2 (a + 1, B )) flag = max (-dfs (a + 1, B), flag); return flag ;}} int main () {freopen ("ball. in "," r ", stdin); freopen (" ball. out "," w ", stdout); scanf (" % d ", & A, & B, & n);/* if (a = 1 &&! Pow2 (a + 1, B) {return 0;} else if (B = 1 &&! Dfs (a, B + 1) {}*/int p = dfs (a, B); if (p = 0) printf ("Missing \ n "); else if (p =-1) printf ("Stas \ n"); else printf ("Masha \ n"); return 0 ;}

Related Article

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.