【思维】LightOj Fibsieve`s Fantabulous Birthday 1008
来源:互联网 发布:python 模块 编辑:程序博客网 时间:2024/05/19 23:10
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
Output for Sample Input
3
8
20
25
Case 1: 2 3
Case 2: 5 4
Case 3: 1 5
按所给的图,给出一个数,给出它的坐标。
AC代码:
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;int main(){ int t; int xp=1; scanf("%d",&t); while(t--){ long long n; scanf("%lld",&n); long long a=sqrt(n); long long ca=ceil(sqrt(n)); long long x,y; if(a&1){ if(n==a*a){ y=a; x=1; } else{ y=a+1; x=n-a*a; if(x>a+1){ y-=(x-a)-1; x=a+1; } } } else{ if(n==a*a){ y=1; x=a; } else{ x=a+1; y=n-a*a; if(y>a+1){ x-=(y-a)-1; y=a+1; } } } printf("Case %d: %lld %lld\n",xp++,x,y); } return 0;}
- 【思维】LightOj Fibsieve`s Fantabulous Birthday 1008
- 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
- 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(规律)
- 监听webview的滑动
- 深入分析JavaWeb Item1 -- JavaWeb开发入门
- C++之UML关系说明图
- Android知识总结:Universal-Imageloader学习笔记2 主业务流程源码分析
- hdu--2674
- 【思维】LightOj Fibsieve`s Fantabulous Birthday 1008
- JAVA_Se异常的学习总结
- 1.单例设计模式(懒汉式,饿汉式,枚举式,双重检测锁式,静态内部
- iptable之我也不知道
- 映射断开网络驱动器
- Android 虚线分割线
- class sun.reflect.NativeMethodAccessorImpl请问这个类在哪里啊
- Codeigniter集成PHPExcel
- Java基本数据类型