• [SPOJ2021] Moving Pebbles


    [SPOJ2021] Moving Pebbles

    题目大意:给你(N)(Stone),两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头,然后移动任意个石子到任意堆中. 谁不能移动了,谁就输了

    Solution

    • n为偶数,这些石子堆都是可以两两配对的石子堆,后手必胜,那么无论如何先手对它移动,后手都可以对另一个配对的石子堆做相应的调整.
    • n为偶数,但是石子不可以两两配对,先手必胜,可以令最高堆与最低堆相同,然后将其他堆的石子数补成两两相同。
    • (n)为奇数,先手必胜,因为先手一定可以操作最高的一堆使得局面变成偶数堆且两两堆数相同。

    错误

    正确

    Code

    #include <cstdio>
    #include <algorithm>
    
    int a[100005];
    
    int read() {
    	int x = 0; char c = getchar();
    	while (c < '0' || c > '9') c = getchar();
    	while (c >= '0' && c <= '9') {
    		x = (x << 3) + (x << 1) + (c ^ 48);
    		c = getchar();
    	}
    	return x;
    }
    
    int main() {
    	int n = read();
    	for (int i = 1; i <= n; ++i) a[i] = read();
    	std::sort(a + 1, a + n + 1);
    	for (int i = 1; i <= n; i += 2)
    		if(a[i] != a[i+1]){
                puts("first player");
                return 0;
            }
    	puts("second player");
    	return 0;
    }
    
  • 相关阅读:
    EJB 笔记
    设计模式
    go 笔记
    破解ssl pinning 抓APP的https数据包
    python读取、写入csv文件
    Python中用正则匹配手机号码
    苹果手机安装charles证书
    mysql在表中插入一个字段
    Python递归调用自己的函数
    mysql查询语句
  • 原文地址:https://www.cnblogs.com/LMSH7/p/9573410.html
Copyright © 2020-2023  润新知