Light OJ - 1008 - Fibsieve`s Fantabulous Birthday
来源:互联网 发布:linux 启动jenkins 编辑:程序博客网 时间:2024/04/29 05:28
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<stdio.h>
#include<math.h>
int main()
{
int t;
long long s,a,b,i,j,u;
scanf("%d",&t);
for(u=1;u<=t;u++)
{
scanf("%lld",&s);
a=sqrt(s);
if(a%2==0)
a-=1;
if(a*a==s)
{
i=1;
j=a;
}
else
{
b=s-a*a;
if(b<=(a+1))
{
i=b;
j=a+1;
}
else if(b<=(2*a+1))
{
i=a+1;
j=2*a+2-b;
}
else if(b<3*a+3)
{
i=a+2;
j=b-2*a-1;
}
else
{
i=4*a+5-b;
j=a+2;
}
}
printf("Case %d: %d %d\n",u,i,j);
}
return 0;
}
- Light OJ 1008- Fibsieve`s Fantabulous Birthday
- Light oj 1008 Fibsieve`s Fantabulous Birthday
- Light OJ - 1008 - Fibsieve`s Fantabulous Birthday
- Light OJ - 1008 - Fibsieve`s Fantabulous Birthday
- light oj 1008 Fibsieve`s Fantabulous Birthday
- LIGHT OJ-1008 Fibsieve`s Fantabulous Birthday
- Light OJ - 1008 - Fibsieve`s Fantabulous Birthday 题解
- Light oj:1008 - Fibsieve`s Fantabulous Birthday【规律】
- Light OJ 1008 Fibsieve`s Fantabulous Birthday【规律】
- Light OJ:1008 Fibsieve's Fantabulous Birthday(规律)
- Light OJ - 1008- Fibsieve`s Fantabulous Birthday 暑期小练习
- Light OJ - 1008 - Fibsieve`s Fantabulous Birthday (数学找规律)
- light oj 1008 - Fibsieve`s Fantabulous Birthday(规律推导)
- light oj 1008 Fibsieve`s Fantabulous Birthday (规律)
- 【Light】[1008]Fibsieve`s Fantabulous Birthday
- Light OJ 1008 Fibsieve`s Fantabulous Birthday(找出数字位置)
- Light OJ - 1008 - Fibsieve`s Fantabulous Birthday(数学,找规律)
- Fibsieve`s Fantabulous Birthday
- 2016年轻人消费洞察
- 加速度传感器的原理和应用:手机翻转、失重检测、运动检测、位置识别
- maven dependency management
- ipairs和pairs区别
- (飛飛五十七)虚函数
- Light OJ - 1008 - Fibsieve`s Fantabulous Birthday
- 乐学成语——导入篇
- 深入理解java中栈,堆常量池。。
- 第15周阅读程序(1)
- STL迭代器的使用、正向、逆向输出双向链表中的所有元素
- House Robber
- 如何禁止listview的item项获得焦点,而让子控件获得焦点
- 欢迎使用CSDN-markdown编辑器
- 实习面试小记-腾讯、阿里、大摩、网易