【ACM】LightOJ - 1008 Fibsieve`s Fantabulous Birthday (找规律,找...)
https://vjudge.net/problem/LightOJ-1008
题目很好理解,第一行表示测试样例的个数,接下来输入一个大于等于1的数,按照格式输出这个数的坐标
蓝色的是 奇数的平方;
红色的是 偶数的平方;
黄色的是对角线:对角线满足规律 n * (n - 1)+ 1,其中 n 为行(列)数;
需要分情况讨论,正好是平方数,n开方后是奇数还偶数,比斜对角线上数大还是小,分五种情况。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
typedef long long ll;
using namespace std;
int main()
{
ll k,T,n,a,b;
cin >> T;
for(k=1;k<=T;k++)
{
cin >> n;
printf("Case %lld: ",k);
a = (ll)sqrt((double)n);
if(a*a == n)
{
if(a & 1)
printf("1 %lld\n",a);
else
printf("%lld 1\n",a);
continue;
}
if(a&1)
{
b = a * (a + 1) + 1;
if(n < b)
printf("%lld %lld\n",(a+1)-(b-n),a+1);
else
printf("%lld %lld\n",a+1,(a+1)-(n-b));
}
else
{
b = a * (a + 1) + 1;
if(n < b)
printf("%lld %lld\n",a+1,(a+1)-(b-n));
else
printf("%lld %lld\n",(a+1)-(n-b),a+1);
}
}
return 0;
}