Light OJ 1008 Fibsieve`s Fantabulous Birthday【规律】
2015-12-01 19:44
483 查看
Fibsieve`s Fantabulous Birthday
PDF (English) | Statistics | Forum |
Time Limit: 0.5 second(s) | Memory Limit: 32 MB |
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 | Output for Sample Input |
3 8 20 25 | Case 1: 2 3 Case 2: 5 4 Case 3: 1 5 |
<span style="font-family:Courier New;font-size:12px;">#include <iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; typedef long long LL; int main() { int t,cnt=0; LL s,c,r; scanf("%d",&t); while(t--) { scanf("%lld",&s); LL tem=s-1; tem=sqrt(tem)+1; c=r=tem; LL tim=tem-1; tem=tem*tem; LL mid=tem-tim; printf("Case %d: ",++cnt); if(c&1) { if(s>mid) r=r-(s-mid); else if(s<mid) c=c-(mid-s); } else { if(s>mid) c=c-(s-mid); else if(s<mid) r=r-(mid-s); } printf("%lld %lld\n",r,c); } return 0; }</span>
相关文章推荐
- 企业应用打包的时候 修改ipa包的bundle identifier
- 禁用驱动签名强制
- 129、Sum Root to Leaf Numbers
- 【Codeforces 343D】Water Tree dfs序建树+线段树
- BZOJ2300: [HAOI2011]防线修建
- hadoop分布式安装在ubuntu下安装JDK
- hadoop分布式安装在ubuntu下安装JDK
- Oracle数据库查询锁表
- centos6之pacemaker 高可用Web使用详解(转)
- 分享我设计的iOS项目目录结构
- Python几个标准类型内建函数
- 条件编译
- 数组和指针
- Oracle数据库导入导出语句
- 备忘——java如何设置全局变量
- android socket简单编程(java在PC本地创建服务器)
- 求矩形和圆柱的体积(用到了接口)
- maven 的几个重要的配置文件:super pom & 生命周期默认绑定的配置文件
- Oracle数据库增加表空间
- 百度地图定位无法获得经纬度的解决方案