UVA10161Ant on a Chessboard

题意:找出所给数字的坐标

思路:对角线上的数符合a = n * (n - 1) + 1,然后从奇偶行的数与对角线上的数的大小关系,推出坐标


 
#include<stdio.h>
#include<math.h>

void found(int x){
	int m = ceil(sqrt(x));
	int num = m * (m - 1) + 1;
	if (m % 2 == 0){
		if(x < num)	
			printf("%d %d\n", m - (num - x), m);	
		else
			printf("%d %d\n", m, m - (x - num));
	}
	else
	{
		if(x < num)	
			printf("%d %d\n", m, m - (num - x));	
		else
			printf("%d %d\n", m - (x - num), m);
	}
}

int main(){
	int n;
	while (scanf("%d", &n) && n)
		found(n);			
	return 0;
}


你可能感兴趣的:(UVA10161Ant on a Chessboard)