lightoj 1008 - Fibsieve`s Fantabulous Birthday
来源:互联网 发布:喵哥成男数据 编辑:程序博客网 时间:2024/05/29 12:30
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
题意
有一个地图旋转出来的(观察可知),查询个数的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 罗旅洲
- lightoj 1008 - Fibsieve`s Fantabulous Birthday
- LightOJ 1008 - Fibsieve`s Fantabulous Birthday
- lightOJ 1008 - Fibsieve`s Fantabulous Birthday
- LightOJ 1008 - Fibsieve`s Fantabulous Birthday (规律)
- 【思维】LightOj Fibsieve`s Fantabulous Birthday 1008
- LightOJ-1008 Fibsieve`s Fantabulous Birthday
- 1008 - Fibsieve`s Fantabulous Birthday (lightoj)
- lightoj 1008 - Fibsieve`s Fantabulous Birthday 乱搞
- LightOJ 1008 Fibsieve`s Fantabulous Birthday
- Lightoj 1008 - Fibsieve`s Fantabulous Birthday
- LightOJ 1008 Fibsieve`s Fantabulous Birthday
- 【LightOJ 1008 Fibsieve`s Fantabulous Birthday】
- lightoj 1008 - Fibsieve`s Fantabulous Birthday
- LightOJ-1008-Fibsieve`s Fantabulous Birthday [规律]
- lightoj 1008 - Fibsieve`s Fantabulous Birthday 【数学 找规律】
- lightoj--1008--Fibsieve`s Fantabulous Birthday(水题)
- 【LightOJ】1008 - Fibsieve`s Fantabulous Birthday(规律)
- lightoj-1008 - Fibsieve`s Fantabulous Birthday【思维】【找规律】
- 使用Java开发高性能网站(二)
- Android APK 更新之路
- CSC 576: Alternating Direction Method for Multipliers (ADMM)
- git#fetch
- git的运作原理
- lightoj 1008 - Fibsieve`s Fantabulous Birthday
- Android JNI编程(八)——体验AS2.2.2编写Jni程序、Java调C、C调Java函数、将C代码中的Log打印至Logcat
- 扑克牌顺序
- 微博分享-姬云鹏
- NodeJS、NPM安装配置步骤(windows版本)
- iOS 9新特性-nonnull,nullable和null_resettable
- java 基础 - 单例创建过程
- 【java】xxx.hbm.xml文件中的many-to-one和one-to-many理解
- ios - UILabel 换行处理 AFnetworking请求的