[BOJ] 1074 Z

Time Lapse : None

1074.cpp

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
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

#define MAXSIZE 32768

int cnt = 0;
int N, x, y;
bool tf = true;

void find(int n, int _x, int _y)
{
if(n==2)
{
if(_x==x&&_y==y)
{
tf = false;
cout<<cnt<<endl;
}
if(_x==x&&_y+1==y)
{
tf = false;
cout<<cnt+1<<endl;
}
if(_x+1==x&&_y==y)
{
tf = false;
cout<<cnt+2<<endl;
}
if(_x+1==x&&_y+1==y)
{
tf = false;
cout<<cnt+3<<endl;
}

cnt += 4;
return ;
}
if(tf) find(n/2,_x,_y);
if(tf) find(n/2,_x,_y+n/2);
if(tf) find(n/2,_x+n/2,_y);
if(tf) find(n/2,_x+n/2,_y+n/2);
}
int main(void)
{
cin>>N>>x>>y;
int n = pow(2,N);
find(n,0,0);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/1074/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.