AT_code_festival_relay_j Color Game 的题解

AT_code_festival_relay_j Color Game 的题解

AT传送门

题目大意

n n n 个距离相等的白色石头,有两人用这些石头做游戏。规则就是每个玩家轮流选择白色石头并将其变为黑色,但是不能从前一回合变黑的石头中选择距离在 k k k 内的石头。无法选择白色石头的玩家失败。在这个游戏中,双方采用最优策略,询问先涂必胜或者后涂必胜。

思路

这是一道较为简单的思维题,我们可以画图分析:

n = 7 n=7 n=7 k = 5 k=5 k=5 时,只需要涂黑中间的石头:

n = 15 n=15 n=15 k = 3 k=3 k=3 时,如图:

注:涂灰的是对手的,涂黑的是自己的。

能看到自己有 4 4 4 块涂黑的,对手有 3 3 3 块涂黑的,最后一块可涂黑的石头是自己涂的,因此也可以先出手必胜。

我们能总结出这些结论:

  1. 如果 k ≥ n ÷ 2 k \ge n \div 2 kn÷2 ,先手方直接把中间的石子涂黑,对方就输了。

  2. 如果 n n n 为奇数,那么最后一定会先手方涂黑一个石子后,后手方无处可下。

  3. 如果 n n n 为偶数,那么最后一定会后手方涂黑一个石子后,先手方无处可下。

代码

#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
#include <string>
#include <cstring>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO {
	inline int read() {
		register int x = 0, f = 1;
		register char c = getchar();
		while (c < '0' || c > '9') {
			if(c == '-') f = -1;
			c = getchar();
		}
		while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
		return x * f;
	}
	inline void write(int x) {
		if(x < 0) putchar('-'), x = -x;
		if(x > 9) write(x / 10);
		putchar(x % 10 + '0');
		return;
	}
}
using namespace fastIO;
int main() {
    int n, k;
    cin >> n >> k;
    if (k >= n / 2) {
		cout << "first" << endl;
	}
    else if (n % 2 == 1) {
    	cout << "first" << endl;
	}
    else {
		cout << "second" << endl;
	}
	return 0;
} 

PS:岛国题目输出后要加空格。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值