-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7326.cpp
More file actions
53 lines (51 loc) · 790 Bytes
/
7326.cpp
File metadata and controls
53 lines (51 loc) · 790 Bytes
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
46
47
48
49
50
51
52
53
// 7326. Number Steps
// 2019.05.21
// 자료구조, 정렬
#include<iostream>
#include<queue>
using namespace std;
int map[5001][5001];
int dx[4] = { 1,-1,1,1 };
int dy[4] = { 1,1,1,-1 };
int main()
{
// -1로 초기화
for (int i = 0; i < 5001; i++)
{
fill(map[i], map[i] + 5001, -1);
}
int x = 0;
int y = 0;
int cnt = 0;
map[x][y] = cnt;
int dir = 0;
// 0,0 부터 5000,5000까지 값 넣을 수 있는곳에 넣어줌
while (1)
{
x += dx[dir];
y += dy[dir];
if (x > 5000 || y > 5000)
{
break;
}
map[x][y] = ++cnt;
dir = (dir + 1) % 4;
}
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
int ans = map[y][x];
if (ans == -1)
{
cout << "No Number" << endl;
}
else
{
cout << ans << endl;
}
}
return 0;
}