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个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...
随机推荐
- linux Ubuntu12 设置root用户登录图形界面
Ubuntu 12.04默认是不允许root登录的,在登录窗口只能看到普通用户和访客登录.以普通身份登陆Ubuntu后我们需要做一些修改,普通用户登录后,修改系统配置文件需要切换到超级用户模式,在终端 ...
- mysql 查询重复值命令
积累备忘啊: ; 从t_maintenanceinfo表查询重复记录的mtiId 和ip字段,以及重复条数
- mvc学习
视频: http://edu.51cto.com/index.php?do=lession&id=14581 博客: http://www.cnblogs.com/chsword/archiv ...
- Nginx、LVS及HAProxy负载均衡软件的优缺点详解
http://www.csdn.net/article/2014-07-24/2820837
- Python生成器与yield
列表推导与生成器表达式 当我们创建了一个列表的时候,就创建了一个可以迭代的对象: >>> squares=[n*n for n in range(3)] >>> f ...
- 关于PHP的十大误解 你中了几个?
作为开发人员,你常常会在网上看到不使用XX的理由之类的新闻.而作为最受欢迎的开源服务器端脚本语言,PHP也难逃这样的命运.殊不知,金无足赤.人无完人,再流行的语言都会存在缺点,或者是误解,因此,有些开 ...
- Innodb MVCC源码实现
1. 概述 MVCC: 即多版本一致性,在事务模型下,使用version控制数据版本,关系型数据库基本都实现了MVCC,以对表数据的读写互不阻塞,增大了并发量. Oracle和MySQL数据库都是使用 ...
- Socket编程(九)
此为网络编程的一个系列,后续会把内容补上.....
- 【express】
app.use(express.favicon(__dirname + '/public/images/favicon.ico'));不支持png格式
- 【转】UINavigationBar 使用总结
原文网址:http://www.jianshu.com/p/f0d3df54baa6 UINavigationBar是我们在开发过程中经常要用到的一个控件,下面我会为大家介绍一些常用的用法. 1. 设 ...