Light OJ 1008

找规律。

  首先令n=sqrt(s),上取整。讨论当n为偶数时,若n*n-s<n则x=n,y=n*n-s+1否则x=-n*n+2*n+s-1,y=n;如果n为奇数,交换x,y即可,对称的。

Sample Input

Sample Output
Case :
Case :
Case :

 

*****************************************************

 #include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long LL;
const int INF = 0xfffffff;
const int maxn = ;
#define max(a,b)(a>b?a:b)
#define min(a,b)(a<b?a:b)
#define lson rt<<1
#define rson rt<<1|1 int main()
{
int T,k=;
long long s,n,a,x,y; scanf("%d", &T); while(T--)
{
scanf("%lld", &s); n=ceil(sqrt(double(s))); a=n*n-s;
if(a<n)
{
x=n;
y=a+;
}
else
{
x=-n*n+*n+s-;
y=n;
} if(n%!=)swap(x,y); printf("Case %d: %lld %lld\n",k++,x,y);
}
return ;
}
上一篇:mina2中IoHandler


下一篇:VS2008中MFC界面编程Caption中文全是乱码的解决办法 -转载