【集训DAY5】【Luogu_P7186】 [CRCI2008-2009] TABLICA && Digital problems【暴力】

【集训DAY5】【Luogu_P7186】 [CRCI2008-2009] TABLICA && Digital problems【暴力】_第1张图片

思路:

我们发现只要那k个数的坐标就行了
每次操作时把该移的都移了就行了

c o d e code code

#include
#include

using namespace std;

const int MAXN = 1005;

int x[MAXN], y[MAXN], n, k, x1[MAXN], y1[MAXN];

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= k; i ++) {
		int g;
		scanf("%d%d%d", &g, &x1[i], &y1[i]);
		if(g % n != 0)
			x[i] = g / n + 1, y[i] = g % n;
		else x[i] = g / n, y[i] = n;
	}
	for(int i = 1; i <= k; i ++) {
		int h = 0, l = 0;
		if(y1[i] < y[i]) h = n - y[i] + y1[i];
			else h = y1[i] - y[i];
		for(int j = i + 1; j <= k; j ++)
			if(x[i] == x[j]) {
				y[j] = y[j] + h;
				if(y[j] > n) y[j] -= n;
			}
		if(x1[i] < x[i]) l = n - x[i] + x1[i];
			else l = x1[i] - x[i];
		for(int j = i + 1; j <= k; j ++)
			if(y1[i] == y[j]) {
				x[j] = x[j] + l;
				if(x[j] > n) x[j] -= n;
			}
		printf("%d\n", h + l);
	}
	return 0;
}

你可能感兴趣的:(题解,c++,题解,数学)