Hdu-6266-hdu 6266 Hakase and Nano (game theory)

Source: Internet
Author: User

Test instructions

There were two people taking stones from a heap of n stones, one of whom could take two times, and the second one could only be taken once. Finally, the man who finished the victory.

Ideas:
type Hakase First after Hakase
1 W L
1 1 W W
1 1 1 (3n) L W
1 1 1 1 (3n+1) W L
1 1 1 1 1 (3n+2) W W
type Hakase First after Hakase
X 1 1 W L
X Y 1 W W
X Y Z W W
X 1 1 1 W L
X Y 1 1 W W
X Y Z 1 W W
X 1 1 1 1 W W
X Y 1 1 1 W W

1. If n = 3t, if each stone heap is 1,a the initiator must lose (1 1 1). There is only one stone heap with a quantity greater than 1, then B initiator a must lose (X 1 1).

2. If n = 3t+1, if only a bunch of persimmon is greater than 1 (X 1 1 1). Then B initiator a must lose.

Write the code according to the conclusion:

Code:
#include<iostream>using namespace std;int main() {    int t, n, d;    scanf("%d", &t);    while(t--) {        bool flag = true;        int cnt = 0, a;        scanf("%d %d", &n, &d);        for(int i = 0; i < n; i++) {            scanf("%d", &a);             if(a >= 2)                cnt++;        }        int x = n % 3;        if(x == 0) {            if(cnt==0 && d==1)                flag = false;            if(cnt==1 && d==2)                flag = false;        }else if(x == 1){            if(cnt<=1 && d==2)                flag = false;        }        if(flag) printf("Yes\n");        else printf("No\n");    }    return 0;}

Hdu-6266-hdu 6266 Hakase and Nano (game theory)

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.