-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDrawingBook.cpp
57 lines (53 loc) · 925 Bytes
/
DrawingBook.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
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
int solve(int n, int p){
int ctrb=0,ctrf=0;
if(p%2==0)
{
for(int i=0;i<=n;i+=2)
{ if(i==p)
break;
ctrf++;
}
}
else
{
for(int j=1;j<=n;j+=2)
{
if(j==p)
break;
ctrf++;
}
}
if(n%2==0)
{
for(int k=n;k>=0;k-=2)
{
if(k==p || k+1==p)
break;
ctrb++;
}
}
else
{
for(int l=n;l>=0;l-=2)
{
if(l==p || l-1==p)
break;
ctrb++;
}
}
if(ctrf<ctrb)
return ctrf;
else
return ctrb;
}
int main() {
int n;
cin >> n;
int p;
cin >> p;
int result = solve(n, p);
cout << result << endl;
return 0;
}