【lightoj1008】数学找规律
C - C 使用long long
Time Limit:500MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status Practice LightOJ 1008 uDebug
Description
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
3
8
20
25
Sample Output
Case 1: 2 3
Case 2: 5 4
Case 3: 1 5
找规律并完美表达,注意细节,写的时候别着急。
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
int main() {
int T,p=0;
scanf("%d",&T);
while(T--) {
LL n;
scanf("%lld",&n);
LL cnt=sqrt(n);
LL ant=n-cnt*cnt;
LL temp=(cnt+1)*(cnt+1)-cnt*cnt;
// printf("%lld %lld--\n",cnt,ant);
printf("Case %d: ",++p);
if(ant==0) {
if((cnt*cnt)&1) {
printf("1 %lld\n",cnt);
// printf("==\n");
} else {
printf("%lld 1\n",cnt);
}
} else {
if((cnt*cnt)&1) {
if(ant<=temp/2) {
printf("%lld %lld\n",ant,cnt+1);
} else {
printf("%lld %lld\n",cnt+1,temp-ant+1);
}
} else {
if(ant<=temp/2) {
printf("%lld %lld\n",cnt+1,ant);
} else {
printf("%lld %lld\n",temp-ant+1,cnt+1);
}
}
}
}
return 0;
}
还没有评论,来说两句吧...