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 |
找规律~~ 比赛的时候太紧张脑袋跟一锅浆糊一样,硬是没推出来。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
int main()
{
//freopen("in.in","r",stdin);
int T;
scanf("%d",&T);
for(int tt=1;tt<=T;tt++)
{
ll s;
scanf("%lld",&s);
//int x,y;
double ss=(double)s*1.0;
int k=sqrt(ss);
//printf("%d\n",k);
if( k*k == s)
{
if(k % 2 == 0) printf("Case %d: %d 1\n",tt,k);
else printf("Case %d: 1 %d\n",tt,k);
}
else
{
int kk=k+1;
int c=kk*kk - s;
if(kk%2 == 0)
{
if(c < kk)
printf("Case %d: %d %d\n",tt,kk,c+1);
else
printf("Case %d: %d %d\n",tt,2*kk-c-1,kk);
}
else
{
if(c < kk)
printf("Case %d: %d %d\n",tt,c+1,kk);
else
printf("Case %d: %d %d\n",tt,kk,2*kk-c-1);
}
}
//printf("Case %d: %d %d\n",tt,ans+1,ans%(ans+1)+1);
}
return 0;
}