zoukankan      html  css  js  c++  java
  • POJ1740 A New Stone Game

    给你N堆石子 两个人轮流进行操作 每个人可以先从一个石子堆里面拿至少一个 然后把这个石子堆的剩余石子分到任意堆中

    拿完石子的人胜  问你谁胜

    只有一堆肯定先手胜 如果有两堆的话 两堆数目相同则后手胜 不同则先手胜 因为先手可以把多的一堆拿到和另外一堆相同的数目

    如果有奇数堆的话 先手可以拿走最大的然后把它分配给其他堆制造必胜的情况 如果是偶数堆的话 只要不是相等的堆有N/2对 先手也可以构造必胜的情况

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<map>
    #include<set>
    #include<vector>
    using namespace std;
    int a[105];
    int main() {
            int n;
            while (scanf("%d", &n) == 1 && n) {
                    for (int i = 1; i <= n; i++) {
                            scanf("%d", &a[i]);
                    }
                    if (n == 1) {
                            cout << 1 << endl;
                            continue;
                    }
                    bool flag = 1;
                    if (n % 2 == 0) {
                            sort(a+1,a+1+n);
                            for (int i = 1; i <= n; i += 2) {
                                    if (a[i] != a[i + 1]) {
                                            flag = 0;
                                            break;
                                    }
                            }
                            if (flag) {
                                    cout << 0 << endl;
                            } else {
                                    cout << 1 << endl;
                            }
                    } else {
                            cout << 1 << endl;
                    }
            }
            return 0;
    }
  • 相关阅读:
    Swift
    ios高质量博客
    Swift
    UML建模
    Swift
    Swift
    IIS建立.net framework4 应用程序池HTTP 错误 500.21
    zz entity framework vs linq to sql
    zz部署wcf iis
    zzIIS站点中部署WCF项目
  • 原文地址:https://www.cnblogs.com/Aragaki/p/11643754.html
Copyright © 2011-2022 走看看