lightoj 1008 - Fibsieve`s Fantabulous Birthday

来源:互联网 发布:喵哥成男数据 编辑:程序博客网 时间:2024/05/29 12:30

Fibsieve had a fantabulous (yes, it's an actual word)birthday party this year. He had so many gifts that he was actually thinking ofnot having a party next year.

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

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

(The numbers in thegrids 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 topredict which cell will light up at a certain time (given in seconds). AssumethatN 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 twonumbers (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

 

题意

 有一个地图旋转出来的(观察可知),查询个数的position。

代码

#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<cmath>using namespace std;long long s,x,y;int main(){int i,j,k,m,n,T,flag;scanf("%d",&T);k=T;while(T--){scanf("%lld",&s);long long luo=sqrt(s-1);flag=luo%2;long long mid=((luo+1)*(luo+1)+(luo*luo+1))/2;if(flag==1){if(s==mid)printf("Case %d: %lld %lld\n",k-T,luo+1,luo+1);else if(s<mid){y=luo+1;x=y-(mid-s);printf("Case %d: %lld %lld\n",k-T,x,y);}else if(s>mid){x=luo+1;y=x-(s-mid);printf("Case %d: %lld %lld\n",k-T,x,y);}}else{if(s==mid)printf("Case %d: %lld %lld\n",k-T,luo+1,luo+1);else if(s<mid){x=luo+1;y=x-(mid-s);printf("Case %d: %lld %lld\n",k-T,x,y);}else if(s>mid){y=luo+1;x=y-(s-mid);printf("Case %d: %lld %lld\n",k-T,x,y);}}}return 0;}

made by 罗旅洲



1 0
原创粉丝点击