Light OJ - 1008 - Fibsieve`s Fantabulous Birthday
2016-06-07 19:11
260 查看
S - S
Time Limit:500MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status
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;
}
Time Limit:500MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status
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;
}
相关文章推荐
- 权限的设计
- 第15周阅读程序(1)
- 实习面试小记-腾讯、阿里、大摩、网易
- C++符号的还原(demangling)
- 如何禁止listview的item项获得焦点,而让子控件获得焦点
- House Robber
- SQL Server地理位置信息计算两点经纬度距离
- (飛飛五十七)虚函数
- STL迭代器的使用、正向、逆向输出双向链表中的所有元素
- bzoj 4423: [AMPPZ2013]Bytehattan
- 加速度传感器的原理和应用:手机翻转、失重检测、运动检测、位置识别
- hdu 5666 Segment(大整数乘法)
- 乐学成语——导入篇
- git 强制回退服务器上的commit
- 数字转换为时、分、秒
- Solr JAVA客户端SolrJ 4.9使用示例教程
- maven dependency management
- 2016年轻人消费洞察
- JDK8 Stream
- ie下css兼容问题