社区讨论

没开数组mle

P1228地毯填补问题参与者 5已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@m1l3ln2q
此快照首次捕获于
2024/09/28 03:10
去年
此快照最后确认于
2025/11/04 18:38
4 个月前
查看原帖
14分,没开任何数组为什么会mle,我不理解
CPP
#include<stdio.h>
#include<iostream>
using namespace std;
int k,K=1,X,Y;

void other(int x, int y, int dir, int step) {
	
	if (step == 0) {
		printf("%d %d %d\n", x, y, dir);
		return;
	}
	else {
		if (dir == 1){
			other(x + step, y + step, 1, step - 1);
			other(x -1-step, y + step, 3, step - 1);
			other(x + step, y -1-step, 2, step - 1);
		}
		if (dir == 3){
			other(x - step, y + step, 3, step - 1);
			other(x + 1+step, y + step, 1, step - 1);
			other(x - step, y - 1-step, 4, step - 1);
		}
		if (dir ==2){
			other(x + step, y - step, 2, step - 1);
			other(x + step, y + step+1, 1, step - 1);
			other(x - step - 1, y - step, 4, step - 1);
		}
		if (dir == 4){
			other(x - step, y - step, 4, step - 1);
			other(x - step, y + step+1, 3, step - 1);
			other(x + step+1, y - step, 2, step - 1);
		}
		other(x, y, dir, step - 1);
	}
}

void sol(int x1, int y1,int x2,int y2,int size) {
	K = K / 2;
	size--;
	if (x1 == x2 && x1 == X && y1 == y2 && y1 == Y)return;
	if (X <= x1 + x2 - K - 1 && Y <= y1 + y2 - K - 1) {
		//printf("P在4区\n");
		other(x1 + x2 - K, y1 + y2 - K, 1, size );
		sol(x1, y1, x1 + x2 - K - 1, y1 + y2 - K - 1, size);
	}
	else if (X > x1 + x2 - K - 1 && Y <= y1 + y2 - K - 1) {
		//printf("P在2区\n");
		other(x1 + x2 - K - 1, y1 + y2 - K, 3, size);
		sol(x1+x2-K, y1, x2, y1 + y2 - K , size);
	}
	else if (X <= x1 + x2 - K - 1 && Y > y1 + y2 - K - 1) {
		//printf("P在3区\n");
		other(x1 + x2 - K, y1 + y2 - K - 1, 2, size);
		sol(x1, y1 + y2 - K, x1 + x2 - K - 1, y2, size);
	}
	else if (X > x1 + x2 - K - 1 && Y > y1 + y2 - K - 1) {
		//printf("P在1区\n");
		other(x1 + x2 - K-1, y1 + y2 - K - 1, 4, size);
		sol(x1 + x2 - K, y1 + y2 - K, x2, y2, size);
	}
}



int main() {
	cin >> k >> X >> Y;
	for (int i = 1; i <= k; i++) {
		K *= 2;
	}
	sol(1, 1, K, K, k);

	return 0;
}


回复

4 条回复,欢迎继续交流。

正在加载回复...