跳到正文

题解

题解:AT_abc184_c [ABC184C] Super Ryuma

__XYXW__约 5 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 5 分钟

版本

  1. v1当前

题解:AT_abc184_c [ABC184C] Super Ryuma

题目传送门

题目大意

给你一颗棋子,你一次可以这么走(只有红点能一步到达):

研究思路

首先要证明:最多3步。

证明:

我们可以先用1~2步斜着走到目标的旁边,然后再走到终点。 得证。

这样就好办了。

答案为0时

只有这一种可能:起点=终点

答案为1时

走一步就行。

答案为2时

斜着走可以 如何判断?判断两个点的行号和两个点的列号的奇偶性是否相等就行了。

还有可能,就是可以走两次满足 ∣a−c∣+∣b−d∣≤3|a-c|+|b-d|\le3 的步骤,总共是 ∣a−c∣+∣b−d∣≤6|a-c|+|b-d|\le6。

还有,就是走一次斜线,再走一次满足 ∣a−c∣+∣b−d∣≤3|a-c|+|b-d|\le3 的步骤。所以:

{∣(a+b)−(c+d)∣≤3∣(a−b)−(c−d)∣≤3\begin{cases} \left|\left(a+b\right)-\left(c+d\right)\right|\le3\\ \left|\left(a-b\right)-\left(c-d\right)\right|\le3 \end{cases}

满足任意一个的,答案也是 22。

如果都不是,那么答案就是 33。

AC Code
C++
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
struct IO{
	void read(char &x){
		x = getchar();
		while (isspace(x)){
			if (x == EOF){
				exit(0);
			}x = getchar();
		}
	}
	void write(char x){
		putchar(x);
	}
	template <typename T>
	void read(T& x){
		x = 0;
		int w = 1;
		char c = getchar();
		while (!isdigit(c)){
			if (c == '-'){
				w = -w;
			}c = getchar();
		}while (isdigit(c)){
			x = (x << 1) + (x << 3) + (c ^ '0');
			c = getchar();
		}if (w == -1){
			x = -x;
		}
	}
	template <typename T>
	void write(T x){
		if (x < 0){
			putchar('-');
			x = -x;
		}if (x > 9){
			write(x / 10);
		}putchar(x % 10 + '0');
	}
	template <typename T, typename... S>
	void read(T& x, S&... xs){
		read(x);
		read(xs...);
	}
	template <typename T, typename... S>
	void write(T x, S... xs){
		write(x);
		write(xs...);
	}
}io;
#define rep(i, l, r, d) for (int i = (l); i <= (r); i += d)
#define rrep(i, r, l, d) for (int i = (r); i >= (l); i -= d)
#define graph(h, i, u) for (node* i = h[u]; i; i = i -> next)
int sx, sy, tx, ty;
int main(){
	io.read(sx, sy, tx, ty);
	if (sx == tx && sy == ty){
		io.write(0);
		return 0;
	}if (sx + sy == tx + ty || sx - sy == tx - ty || abs(sx - tx) + abs(sy - ty) <= 3){
		io.write(1);
		return 0;
	}if ((sx + tx) % 2 == (sy + ty) % 2){
		io.write(2);
		return 0;
	}if (abs(sx - tx) + abs(sy - ty) <= 6){
		io.write(2);
		return 0;
	}if (abs((sx + sy) - (tx + ty)) <= 3){
		io.write(2);
		return 0;
	}if (abs((sx - sy) - (tx - ty)) <= 3){
		io.write(2);
		return 0;
	}io.write(3);
	return 0;
}//抱歉,我不太喜欢写注释

record:

原文