uva 10161

题意:找规律,自己慢慢琢磨吧
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int n ;
int main()
{
	int hang,lie;
	while(scanf("%d",&n) && n )
	{
		if(n == 1)
		{
			printf("1 1\n");
			continue;
		}
		int sign;
		for(int i = 1 ; ; i++)
		{
			if((n>=pow(i,2)) && (n<=pow(i+1,2)))
			{
				sign = i+1;
				break;
			}
		}
		int cnt1 = pow(sign,2);
		int a = cnt1 - n ;
		if(a > sign - 1)
		{
			if(sign % 2 == 0 )
			{
				hang = sign ;
				lie = sign- (a - sign + 1);
			}
			else
			{
				lie = sign ;
				hang = sign- (a - sign + 1);
			}
		}
		else 
		{
			if(sign % 2 == 0)
			{
				lie = sign ;
				hang = a + 1;
			}
			else 
			{
				hang = sign ;
				lie = a + 1 ;
			}
		}
		printf("%d %d\n",lie,hang);
	}
	return 0 ;
}


你可能感兴趣的:(uva 10161)