zoukankan      html  css  js  c++  java
  • upc组队赛2 Hakase and Nano【思维博弈】

    Hakase and Nano

    题目描述

    Hakase and Nano are playing an ancient pebble game (pebble is a kind of rock). There are n packs of pebbles, and the i-th pack contains ai pebbles. They take turns to pick up pebbles. In each turn, they can choose a pack arbitrarily and pick up at least one pebble in this pack. The person who takes the last pebble wins.
    This time, Hakase cheats. In each turn, she must pick pebbles following the rules twice continuously.
    Suppose both players play optimally, can you tell whether Hakase will win?

    输入

    The first line contains an integer T (1≤T≤20) representing the number of test cases.
    For each test case, the fi rst line of description contains two integers n(1≤n≤106) and d (d = 1 or d = 2). If d = 1, Hakase takes first and if d = 2, Nano takes first. n represents the number of pebble packs.
    The second line contains n integers, the i-th integer ai (1≤ai≤109) represents the number of pebbles in the i-th pebble pack.

    输出

    For each test case, print “Yes” or “No” in one line. If Hakase can win, print “Yes”, otherwise, print “No”.

    样例输入

    2
    3 1
    1 1 2
    3 2
    1 1 2
    

    样例输出

    Yes
    No
     
    

    题解

    以为是NIM,一直在想怎么控制数量相同,然后自己写了几组数据找规律发现总是能赢..

    就去找会输的情况,发现只有很多1的时候才会输

    先手的话只有全部是1,并且堆数得是3的倍数才会输

    后手就是在先手的情况下加一步,

    有一堆数量不为1的堆,其他全部为1 并且堆数得是3的倍数

    或者 ,堆数得是3的倍数 + 1 ,有一堆的数量任意,其他全为1

    代码

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i,a,n) for(int i=a;i<n;i++)
    #define memset(x,y) memset(x,y,sizeof(x))
    #define memcpy(x,y) memcpy(x,y,sizeof(y))
    #define all(x) x.begin(),x.end()
    #define readc(x) scanf("%c",&x)
    #define read(x) scanf("%d",&x)
    #define read2(x,y) scanf("%d%d",&x,&y)
    #define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define print(x) printf("%d
    ",x)
    #define lowbit(x) x&-x
    #define lson(x) x<<1
    #define rson(x) x<<1|1
    #define pb push_back
    #define mp make_pair
    typedef pair<int,int> P;
    typedef long long LL;
    typedef long long ll;
    const double eps=1e-8;
    const double PI = acos(1.0);
    const int INF = 0x3f3f3f3f;
    const int inf = 0x3f3f3f3f;
    const int MOD = 1e9+7;
    const ll mod = 998244353;
    const int MAXN = 1e6+7;
    const int maxm = 1;
    const int maxn = 100000+10;
    int T;
    ll a[maxn];
    int flag ;
    int n,d;
    int cnt ;
    int main(){
      read(T);
      while(T--){
        read2(n,d);
        cnt = 0;
        for(int i = 0; i < n; i++){
          scanf("%lld",&a[i]);
          if(a[i] != 1) cnt ++;
        }
        flag = 1;
        if(d == 1){
          if(n % 3 == 0 && cnt == 0) flag = 0;
        }
        if(d == 2) {
          if(n % 3 == 0 && cnt == 1) flag = 0;
          else if(n % 3 == 1 && cnt <= 1) flag = 0;
        }
        if(flag) cout << "Yes" << endl;
        else cout << "No" << endl;
      }
    }
    
  • 相关阅读:
    3.struts2接收页面传参的三种方式
    2.struts2访问web资源(在struts2中获取session,request等等)
    1.struts2原理和入门程序
    3.springMVC+spring+Mybatis整合Demo(单表的增删该查,这里主要是贴代码,不多解释了)
    2.springMVC+spring+Mybatis整合
    1.springMVC+spring+Mybatis的整合思路
    clipboard
    SDN&NFV
    linux命令速查
    todo
  • 原文地址:https://www.cnblogs.com/llke/p/10799872.html
Copyright © 2011-2022 走看看