light oj 1008 - Fibsieve`s Fantabulous Birthday
Time Limit: 0.5 second(s) | Memory Limit: 32 MB |
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 |
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1008
算是道模拟题吧!找出数的排列顺序模拟下即可
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define LL long long
#define DD double
#define MAX 20000000
using namespace std;
int main()
{
int t,k;
DD n;
LL m,j,i;
scanf("%d",&t);
k=1;
while(t--)
{
scanf("%lf",&n);
DD ans=sqrt(n);
LL ant=(LL)(ans);
printf("Case %d: ",k++);
if(ans==ant)
{
if(ant%2==0)
printf("%lld 1\n",ant);
else if(ant&1)
printf("1 %lld\n",ant);
}
else
{
LL sum=pow(ant+1,2);
LL sun=pow(ant,2);
LL flag=(LL)(sum-n);
if(flag==ant)
printf("%lld %lld\n",ant+1,ant+1);
else if(flag<ant)
{
if((ant+1)%2==0)
printf("%lld %lld\n",ant+1,flag+1);
else
printf("%lld %lld\n",flag+1,ant+1);
}
else
{
if((ant+1)%2==0)
printf("%lld %lld\n",(sum-sun)-flag,ant+1);
else
printf("%lld %lld\n",ant+1,(sum-sun)-flag);
}
}
}
return 0;
}
light oj 1008 - Fibsieve`s Fantabulous Birthday的更多相关文章
- [LOJ 1008] Fibsieve`s Fantabulous Birthday
A - Fibsieve`s Fantabulous Birthday Time Limit:500MS Memory Limit:32768KB 64bit IO Format:%l ...
- Light OJ 1008
找规律. 首先令n=sqrt(s),上取整.讨论当n为偶数时,若n*n-s<n则x=n,y=n*n-s+1否则x=-n*n+2*n+s-1,y=n;如果n为奇数,交换x,y即可,对称的. Sam ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
- Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩
题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...
随机推荐
- Jquery-DataTable 使用介绍
http://dt.thxopen.com/example/server_side/simple.html
- POJ2531——Network Saboteur(随机化算法水一发)
Network Saboteur DescriptionA university network is composed of N computers. System administrators g ...
- Android TabHost 动态修改图标或者动态改变标题
那时客户需要实现在TabHost标题上动态显示从数据库获取的个数.起初这样思考的,从数据库 获取个数是非常简单,但是要把获取的个数显示在TabHost标题,思前想后,想用Handler来异步实现消息传 ...
- 有关PHP 10条有用的建议
1.使用ip2long() 和long2ip()函数来把IP地址转化成整型存储到数据库里. 这种方法把存储空间降到了接近四分之一(char(15)的15个字节对整形的4个字节),计算一个特定的地址是不 ...
- perl next和last
跳出控制结构:next和last next 和last 操作符运维你在循环中改变程序执行的方向,你可能经常会遇到一些的特殊情况, 碰到这种情况时你希望跳过它,或者像退出循环. 比如当你处理Unix 账 ...
- (转)linux 技巧:使用 screen 管理你的远程会话
转自:http://www.ibm.com/developerworks/cn/linux/l-cn-screen/index.html 你是不是经常需要 SSH 或者 telent 远程登录到 Li ...
- Ubuntu设置中文
Ubuntu设置中文:需要联网下载中文包,不然无法设置中文系统. 进去系统后再右上角有个齿轮图标点击,找到系统设置(System Settings)点击弹出一个界面,找到Language Suppor ...
- poj1026Cipher(置换群)
链接 找循环节 然后所有子循环节的最小公倍数就是总的循环节 找结果的时候也按一个个置换来进行转换 不然也TLE #include <iostream> #include<cstdio ...
- mysql 幻读
幻读(Phantom Read) 是指当用户读取某一范围的数据行时,B事务在该范围内插入了新行,当用户再读取该范围的数据行时,会发现有新的“幻影”行.InnoDB和Falcon存储引擎通 过多版本并发 ...
- function 的声明
<?php function test() { echo "abc"; } test(); ?> 结论: 一 编译 a.对 函数声明进行词法分析和语法分析:在语法分析中 ...