跳到正文

题解

题解 P4101 【[HEOI2014]人人尽说江南好 】

用户 54017约 4 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 4 分钟
获赞
2
题目
P4101

版本

仅有当前版本

发一篇比较好理解的..

直接模拟即可

注意m为偶数和奇数是的情况不同,需要分情况讨论

(这就是100多行的原因(主要是因为我太蒟蒻了))

我是不会说我打了一个多小时的,哼唧

献上蒟蒻代码

C++
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define _ 0
#define ll long long
using namespace std;
inline int read()
{
	ll w = 0;
	ll x = 0;
	char ch = getchar();
	while (ch<'0' || ch>'9')
	{
		w |= ch == '-';
		ch = getchar();
	}
	while (ch >= '0'&&ch <= '9')
	{
		x = (x << 3) + (x << 1) + (ch ^ 48);
		ch = getchar();
	}
	return w ? -x : x;
}
ll t;
int main()
{
	//freopen("game.in","r",stdin);
	//freopen("game.out","w",stdout);
	t = read();
	while (t--)
	{
		ll n, m;
		n = read(); m = read();
		ll num = n / m;//num表示它可以分为多少块
		if (num == 0)
		{
			if (n % 2 == 0)
			{
				printf("0\n");
				continue;
			}
			else
			{
				printf("1\n");
				continue;
			}
		}
		if (num == n)//特判m==1的情况
		{
			printf("1\n");
			continue;
		}
		if (n%m == 0)
		{
			if (m % 2 == 1)
			{
				printf("1\n");
				continue;
			}
			else
			{
				if (num % 2 == 1)
				{
					printf("0\n");
					continue;
				}
				else
				{
					printf("1\n");
					continue;
				}
			}
		}
		else
		{
			if (m % 2 == 1)
			{
				if ((n - m * num) % 2 == 0)
				{
					printf("0\n");
					continue;
				}
				else
				{
					printf("1\n");
					continue;
				}
			}
			else
			{
				if (num % 2 == 0)
				{
					if ((n - m * num) % 2 == 0)
					{
						printf("0\n");
						continue;
					}
					else
					{
						printf("1\n");
						continue;
					}
				}
				else
				{
					if ((n - m * num) % 2 == 1)
					{
						printf("0\n");
						continue;
					}
					else
					{
						printf("1\n");
						continue;
					}
				}
			}
		}
	}
	//fclose(stdin);fclose(stdout);
	return ~~(0 ^ _ ^ 0);
}


如有错误敬请dalao们指正。。

原文