QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#462499#556. 骑士LXl491214100 ✓19ms24480kbC++141.5kb2024-07-03 20:19:572024-07-03 20:19:58

Judging History

你现在查看的是最新测评结果

  • [2024-07-03 20:19:58]
  • 评测
  • 测评结果:100
  • 用时:19ms
  • 内存:24480kb
  • [2024-07-03 20:19:57]
  • 提交

answer

#include <iostream>
#include <utility>
#include <cstdlib>
using namespace std;
constexpr const int d[][2]{{-2, -1}, {-2, 1}, {-1, -2}, {-1, 2}, {2, -1}, {2, 1}, {1, -2}, {1, 2}};
bool book[505][505];
int n, m, K, dis[505][505];
pair<int, int> path[250052];
void DFS(const int step, const int x, const int y)
{
	if (step <= K)
	{
		if (x != n || y != m)
		{
			book[x][y] = 1;
			for (const auto &i : d)
			{
				const int nx = x + i[0], ny = y + i[1];
				if ((1 <= nx && nx <= n) && (1 <= ny && ny <= m) && !book[nx][ny] && step + dis[nx][ny] <= K)
				{
					path[step].first = nx;
					path[step].second = ny;
					DFS(step + 1, nx, ny);
				}
			}
			book[x][y] = 0;
		}
	}
	else if (x == n && y == m)
	{
		for (int i = 1; i <= K; ++i)
			cout << path[i].first << ' ' << path[i].second << '\n';
		exit(0);
	}
	return;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> m >> K;
	for (int i = 1; i <= n; ++i)
	{
		auto &dis_i = dis[i];
		for (int j = 1; j <= m; ++j)
			dis_i[j] = -2147483647;
	}
	dis[path[1].first = n][path[1].second = m] = 0;
	for (int head = 1, tail = 2; head < tail; ++head)
	{
		const int x = path[head].first, y = path[head].second;
		for (const auto &i : d)
		{
			const int nx = x + i[0], ny = y + i[1];
			if ((1 <= nx && nx <= n) && (1 <= ny && ny <= m) && dis[nx][ny] == -2147483647)
			{
				dis[path[tail].first = nx][path[tail].second = ny] = dis[x][y] + 1;
				++tail;
			}
		}
	}
	DFS(1, 1, 1);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 0ms
memory: 3728kb

input:

8 8 48

output:

3 2
1 3
3 4
1 5
3 6
1 7
3 8
2 6
1 4
3 3
1 2
3 1
2 3
4 2
6 1
5 3
4 1
2 2
4 3
2 4
1 6
3 5
2 7
4 6
2 5
4 4
6 3
5 1
7 2
6 4
4 5
3 7
5 6
4 8
6 7
5 5
4 7
6 6
5 4
7 3
5 2
7 1
8 3
7 5
8 7
6 8
7 6
8 8

result:

ok good answer!

Test #2:

score: 10
Accepted
time: 0ms
memory: 3580kb

input:

9 8 17

output:

3 2
1 3
3 4
1 5
3 6
1 7
3 8
2 6
1 4
3 3
1 2
3 1
2 3
4 4
6 5
8 6
9 8

result:

ok good answer!

Test #3:

score: 10
Accepted
time: 0ms
memory: 3600kb

input:

9 10 63

output:

3 2
1 3
3 4
1 5
3 6
1 7
3 8
1 9
3 10
2 8
1 6
3 5
1 4
3 3
1 2
3 1
2 3
4 2
6 1
5 3
4 1
2 2
4 3
2 4
4 5
2 6
1 8
3 7
2 5
4 4
6 3
5 1
7 2
6 4
5 2
7 1
9 2
7 3
5 4
4 6
2 7
4 8
2 9
4 10
6 9
5 7
4 9
6 8
4 7
3 9
5 8
7 7
5 6
7 5
6 7
5 5
7 4
6 2
8 3
9 5
7 6
8 8
9 10

result:

ok good answer!

Test #4:

score: 10
Accepted
time: 1ms
memory: 5696kb

input:

8 12 20

output:

3 2
1 3
3 4
1 5
3 6
1 7
3 8
1 9
3 10
1 11
3 12
2 10
1 8
3 7
1 6
3 5
5 6
6 8
7 10
8 12

result:

ok good answer!

Test #5:

score: 10
Accepted
time: 0ms
memory: 3700kb

input:

16 16 192

output:

3 2
1 3
3 4
1 5
3 6
1 7
3 8
1 9
3 10
1 11
3 12
1 13
3 14
1 15
3 16
2 14
1 12
3 11
1 10
3 9
1 8
3 7
1 6
3 5
1 4
3 3
1 2
3 1
2 3
4 2
6 1
5 3
4 1
2 2
4 3
2 4
4 5
2 6
4 7
2 8
4 9
2 10
4 11
2 12
1 14
3 13
2 11
4 10
2 9
4 8
2 7
4 6
2 5
4 4
6 3
5 1
7 2
6 4
5 2
7 1
9 2
7 3
5 4
7 5
5 6
7 7
5 8
7 9
5 10
4 12
...

result:

ok good answer!

Test #6:

score: 10
Accepted
time: 15ms
memory: 24364kb

input:

500 499 187125

output:

3 2
1 3
3 4
1 5
3 6
1 7
3 8
1 9
3 10
1 11
3 12
1 13
3 14
1 15
3 16
1 17
3 18
1 19
3 20
1 21
3 22
1 23
3 24
1 25
3 26
1 27
3 28
1 29
3 30
1 31
3 32
1 33
3 34
1 35
3 36
1 37
3 38
1 39
3 40
1 41
3 42
1 43
3 44
1 45
3 46
1 47
3 48
1 49
3 50
1 51
3 52
1 53
3 54
1 55
3 56
1 57
3 58
1 59
3 60
1 61
3 62
1 6...

result:

ok good answer!

Test #7:

score: 10
Accepted
time: 19ms
memory: 24480kb

input:

500 500 187500

output:

3 2
1 3
3 4
1 5
3 6
1 7
3 8
1 9
3 10
1 11
3 12
1 13
3 14
1 15
3 16
1 17
3 18
1 19
3 20
1 21
3 22
1 23
3 24
1 25
3 26
1 27
3 28
1 29
3 30
1 31
3 32
1 33
3 34
1 35
3 36
1 37
3 38
1 39
3 40
1 41
3 42
1 43
3 44
1 45
3 46
1 47
3 48
1 49
3 50
1 51
3 52
1 53
3 54
1 55
3 56
1 57
3 58
1 59
3 60
1 61
3 62
1 6...

result:

ok good answer!

Test #8:

score: 10
Accepted
time: 14ms
memory: 18556kb

input:

500 500 125000

output:

3 2
1 3
3 4
1 5
3 6
1 7
3 8
1 9
3 10
1 11
3 12
1 13
3 14
1 15
3 16
1 17
3 18
1 19
3 20
1 21
3 22
1 23
3 24
1 25
3 26
1 27
3 28
1 29
3 30
1 31
3 32
1 33
3 34
1 35
3 36
1 37
3 38
1 39
3 40
1 41
3 42
1 43
3 44
1 45
3 46
1 47
3 48
1 49
3 50
1 51
3 52
1 53
3 54
1 55
3 56
1 57
3 58
1 59
3 60
1 61
3 62
1 6...

result:

ok good answer!

Test #9:

score: 10
Accepted
time: 6ms
memory: 6936kb

input:

499 499 1998

output:

3 2
1 3
3 4
1 5
3 6
1 7
3 8
1 9
3 10
1 11
3 12
1 13
3 14
1 15
3 16
1 17
3 18
1 19
3 20
1 21
3 22
1 23
3 24
1 25
3 26
1 27
3 28
1 29
3 30
1 31
3 32
1 33
3 34
1 35
3 36
1 37
3 38
1 39
3 40
1 41
3 42
1 43
3 44
1 45
3 46
1 47
3 48
1 49
3 50
1 51
3 52
1 53
3 54
1 55
3 56
1 57
3 58
1 59
3 60
1 61
3 62
1 6...

result:

ok good answer!

Test #10:

score: 10
Accepted
time: 19ms
memory: 21620kb

input:

499 500 157873

output:

3 2
1 3
3 4
1 5
3 6
1 7
3 8
1 9
3 10
1 11
3 12
1 13
3 14
1 15
3 16
1 17
3 18
1 19
3 20
1 21
3 22
1 23
3 24
1 25
3 26
1 27
3 28
1 29
3 30
1 31
3 32
1 33
3 34
1 35
3 36
1 37
3 38
1 39
3 40
1 41
3 42
1 43
3 44
1 45
3 46
1 47
3 48
1 49
3 50
1 51
3 52
1 53
3 54
1 55
3 56
1 57
3 58
1 59
3 60
1 61
3 62
1 6...

result:

ok good answer!