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). Assumethat 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 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 罗旅洲
本文介绍了一种算法,用于预测特殊棋盘上灯亮起的确切位置。该棋盘为NxN大小,并且每个单元格内有一盏灯,会按照特定规律依次亮起。通过输入指定的时间秒数,算法能够确定此时哪一盏灯被点亮。
2239

被折叠的 条评论
为什么被折叠?



