zoukankan      html  css  js  c++  java
  • BZOJ 1982 Moving Pebbles

    首先我们假设只有两堆,

    容易发现当且仅当两堆相等时,先手必败

    否则先手必胜

    然后我们猜测一下原因:

    ->当两堆相等时,无论先手怎么做,后手总能使两堆相等,且必败态为0,0

    推广一下:

    当所有的石子堆可以两两配对且配对的两两相等时,先手必败

    否则先手必胜

    证明一下:

    1、当出现两两可以配对且相等的情况时,由两堆相等的情况可以推论,无论先手怎么做,后手总能使局面回到两两配对且相等的情况

    2、如果不是两两可以配对且相等的情况时,先手总能使局面变成两两配对且相等

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    const int maxn=100010;
    int n;
    int a[maxn];
    
    int main(){
        while(scanf("%d",&n)==1){
            for(int i=1;i<=n;++i)scanf("%d",&a[i]);
            if(n&1){printf("first player
    ");continue;}
            sort(a+1,a+n+1);
            bool f=false;
            for(int i=2;i<=n;i+=2){
                if(a[i]!=a[i-1]){f=true;break;}
            }
            if(f)printf("first player
    ");
            else printf("second player
    ");
        }return 0;
    }
    

      

  • 相关阅读:
    手机兼容性测试
    Monkey测试
    ADB常用指令
    ADB移动端测试
    关于虚拟网卡V1,V8的问题
    1
    排序算法
    查找算法
    二叉树的计算
    队列
  • 原文地址:https://www.cnblogs.com/joyouth/p/5334932.html
Copyright © 2011-2022 走看看