UVA 10161 Ant on a Chessboard
题目大意:写出题目给出的图的第n步的坐标
解题思路:看图找找规律
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
int main() {
double a;
long long int x, y;
while(scanf("%lf", &a)) {
if(a == 0)
break;
long long int m =(int)sqrt(a);
long long int s = (int)a - m * m;
if(m % 2 == 0) {
x = m;
y = 1;
if(s <= m + 1 && s > 0) {
x = x + 1;
y = y + s - 1;
}
else if(s > m + 1) {
x = x + 1 - s + m + 1;
y = y + m;
}
}
else {
x = 1;
y = m;
if(s <= m + 1 && s > 0) {
y = y + 1;
x = x + s - 1;
}
else if(s > m + 1) {
y = y + 1 - s + m + 1;
x = x + m;
}
}
printf("%lld %lld\n", x, y);
}
return 0;
}