您的位置:首页 > 其它

Light OJ 1008 Fibsieve`s Fantabulous Birthday【规律】

2015-12-01 19:44 483 查看

Fibsieve`s Fantabulous Birthday



PDF (English)StatisticsForum
Time Limit: 0.5 second(s)Memory Limit: 32 MB
Fibsieve had a fantabulous (yes, it's an actual word) birthday party this year. He had so many gifts that he was actually thinking of not having a party next year.

Among these gifts there was an N x N glass chessboard that had a light in each of its cells. When the board was turned on a distinct cell would light up every second, and then go dark.

The cells would light up in the sequence shown in the diagram. Each cell is marked with the second in which it would light up.



(The numbers in the grids stand for the time when the corresponding cell lights up)
In the first second the light at cell (1, 1) would be on. And in the 5th second the cell (3, 1) would be on. Now, Fibsieve is trying to predict which cell will light up at a certain time (given in seconds). Assume that N is large enough.

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case will contain an integer S (1 ≤ S ≤ 1015) which stands for the time.

Output

For each case you have to print the case number and two numbers (x, y), the column and the row number.

Sample Input

Output for Sample Input

3

8

20

25

Case 1: 2 3

Case 2: 5 4

Case 3: 1 5

恩,题目大意就是说,上面方格里的数字代表该方格灯亮的那一秒,给定一时间,问该时刻哪个方格的灯亮,输出方格是坐标,就规律,很好找。

<span style="font-family:Courier New;font-size:12px;">#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long LL;
int main()
{
int t,cnt=0;
LL s,c,r;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&s);
LL tem=s-1;
tem=sqrt(tem)+1;
c=r=tem;
LL tim=tem-1;
tem=tem*tem;
LL mid=tem-tim;
printf("Case %d: ",++cnt);
if(c&1)
{
if(s>mid)
r=r-(s-mid);
else if(s<mid)
c=c-(mid-s);
}
else
{
if(s>mid)
c=c-(s-mid);
else if(s<mid)
r=r-(mid-s);
}
printf("%lld %lld\n",r,c);
}
return 0;
}</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: