-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva10920.cpp
More file actions
42 lines (32 loc) · 716 Bytes
/
uva10920.cpp
File metadata and controls
42 lines (32 loc) · 716 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
#include<iostream>
#include<cstdio>
using namespace std;
void getCoordinates(int sz, int p) {
int x,y, i = 1;
while ( i*i < p) i += 2;
y = x = (sz+1)/2 + i/2;
int dd = i*i - p; //how much i*i has gone past p
int dx = 0, dy = -1, d = i - 1;
while (dd > 0) { //simulate clockwise rotation by dd steps
dd--;
d--;
y += dy;
x += dx;
if (d == 0) {
d = i-1;
int t = dx;
dx = dy;
dy = -t;
}
}
printf("Line = %d, column = %d.\n", y, x);
}
int main() {
int sz, p;
while(true) {
cin >> sz >> p;
if (sz == 0)
break;
getCoordinates(sz,p);
}
}