[Uoj round#4 A] [#51] New Year's Day three games

Source: Internet
Author: User

Title Link: UOJ-51

This problem is said to be similar to CF 39E.

Problem analysis

A look at the title description, ah, game theory, not! Wait for 0 to explode ...

At this time, xcj god Ben saved me, he said, this problem can be directly searched AH.

Attention! is a memory search with a status of (a, B).

This is the case: we push backwards from behind, and for a state that cannot add a or B (a, b), the person who is walking will fail. This is the state of termination.

And for a state that is not signaled (a, b), there may be two successive states (A + 1, b) | | (A, B + 1), we recursive first to find out whether these two successor States will be defeated or win.

If one of the two successive states is defeated, then there is a way to make the next person will fail, then will certainly go that state (because everyone is smart enough), the current state is to win.

Otherwise, no matter how to choose, the next person to go to win, then the current state is going to fail.

Note that if a successor State is not legal, then it is considered a winning state, because the current cannot go that way.

It should be noted that when B = 1, the legal A has n, can not be searched and can not be stored, we divide the state of B = 1 into two categories:

1) a <= sqrt (n) in this state, B may increase, so it is treated like any other state.

2) a > sqrt (n) Such a state, B is not added, directly to see the n-a of the odd and even better. Each time you use this state, do it alone.

This will be able to find all the feasible status of the winning or losing attribute, because for each B, the number of feasible a difference is too large, we use a vector for each B to save the answer to all feasible a (STL is good!). )。

It's good to have a direct output for each query.

The special attention is! Must remember to search Ah! No memory of the tle to explode Ah!! The status of repeated search too many too many Ah!!

Error writing code: This determines the successor status if (DFS (x + 1, y) && dfs (x, y + 1)) This is absolutely not possible!! After a DFS (x, y+1) is placed after &&, as long as the previous value is true, the following DFS directly does not call!! On my knees!!

Code
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath > #include <algorithm> #include <vector>using namespace std;const int maxn = 1000000 + 5;int N, M, A, B, Sqrt N, top;vector<int> e[35];typedef Long long ll;bool Pow (int a, int b) {LL F, ret;f = A; ret = 1ll;while (b) {if (b &A mp 1) {ret *= f;if (Ret > N) return true;} b >>= 1;f *= f;} if (Ret > N) return True;return false;} BOOL DFS (int x, int y) {if (Y! = 1 && (int) e[y].size () > x && e[y][x]! = 0) return (e[y][x] = = 1); if (P ow (x, y)) return true;if (y = = 1 && x > Sqrtn) {if ((n-x) & 1) return true;else return false; BOOL Flag1, FLAG2; FLAG1 = DFS (x + 1, y); Flag2 = DFS (x, y + 1), while ((int) e[y].size () <= x) e[y].push_back (0), if (Flag1 && Flag2) {e[y][x] = -1;return false;} else {E[y][x] = 1;return true;}} BOOL Willwin (int x, int y) {if (y = = 1 && x > Sqrtn) {if ((n-x) & 1) return True; else return false;} Return (e[y][x] = = 1);} int main () {scanf ("%d%d", &n, &m); SQRTN = (int) sqrt (n * 1.0);D FS (2, 1), for (int i = 1; I <= m; ++i) {scanf ("%d%d", &a, &b); if (Willwin (A, b)) PRI NTF ("yes\n"), Else printf ("no\n");} return 0;}

  

[Uoj round#4 A] [#51] New Year's Day three games

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.