50035. Traversal

難度:3/5 Used Time: 11:54

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define swap(x, y) {int t = (x); (x) = (y); (y) = t;}

int m, n, start_x, start_y;

void solve(){
int now_x = start_x, now_y = start_y;
printf("%d %d\n", now_x, now_y);
while(true){
if(now_x == 0){
if(now_y == 0) now_x++;
else now_y--;
}
else{
if(now_x == 1 && now_y == n - 1){
now_x--;
}
else if(now_y % 2 == 0){
if(now_x == m - 1) now_y++;
else now_x++;
}
else{
if(now_x == 1) now_y++;
else now_x--;
}
}

printf("%d %d\n", now_x, now_y);
if(now_x == start_x && now_y == start_y) break;
}
}

int main(){
while(scanf("%d %d %d %d", &m, &n, &start_x, &start_y) != EOF){
solve();
}
}

// OOOO
// OOOO
// OOOO

C

50035. Traversal
https://aaronlin1229.github.io/judgegirl_50035/
Author
Akizumi
Posted on
July 17, 2023
Licensed under