A - Fibsieve`s Fantabulous Birthday

Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

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

3

8

20

25

Sample Output

Case 1: 2 3

Case 2: 5 4

Case 3: 1 5

题意:给出一张图,以及一个点,求出这个点的坐标

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
#define ll long long ll n; void solve()
{
ll floor=(ll)sqrt(n);
if(floor*floor!=n) floor++; //确定层数
ll dir=floor&; //确定方向,0表示左右下,1表示下上左
ll num=n-((floor-)*(floor-)); //当前层序号
if(dir==)
{
if(num<=floor)
{
printf("%lld %lld\n",num,floor);
}
else
{
num=floor-(num-floor);
printf("%lld %lld\n",floor,num);
}
}
else
{
if(num<=floor)
{
printf("%lld %lld\n",floor,num);
}
else
{
num=floor-(num-floor);
printf("%lld %lld\n",num,floor);
}
}
}
int main()
{
int T,iCase=;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
printf("Case %d: ",iCase++);
solve();
}
return ;
}

[LOJ 1008] Fibsieve`s Fantabulous Birthday的更多相关文章

  1. light oj 1008 - Fibsieve`s Fantabulous Birthday

    1008 - Fibsieve`s Fantabulous Birthday   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Me ...

  2. Fibsieve`s Fantabulous Birthday LightOJ - 1008(找规律。。)

    Description 某只同学在生日宴上得到了一个N×N玻璃棋盘,每个单元格都有灯.每一秒钟棋盘会有一个单元格被点亮然后熄灭.棋盘中的单元格将以图中所示的顺序点亮.每个单元格上标记的是它在第几秒被点 ...

  3. [LightOJ1008]Fibsieve`s Fantabulous Birthday 题解

    前言 扫了一眼网上的题解,都是找规律. 估计就我一个蒟蒻在打二分. 题解 设一个" ┐"形为一层. 我们二分查找该数在那一层,然后就可以直接计算它的位置了. 代码 #include ...

  4. LightOJ Beginners Problems 部分题解

    相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...

  5. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  6. lightoj--1008--Fibsieve`s Fantabulous Birthday(水题)

    Fibsieve`s Fantabulous Birthday Time Limit: 500MS   Memory Limit: 32768KB   64bit IO Format: %lld &a ...

  7. LightOJ-1008-Fibsieve`s Fantabulous Birthday(推公式)

    链接: https://vjudge.net/problem/LightOJ-1008 题意: Fibsieve had a fantabulous (yes, it's an actual word ...

  8. HDOJ 1008. Elevator 简单模拟水题

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  9. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

随机推荐

  1. POJ 2127 Greatest Common Increasing Subsequence -- 动态规划

    题目地址:http://poj.org/problem?id=2127 Description You are given two sequences of integer numbers. Writ ...

  2. csdn博客刷粉代码

    原理是当有访客访问博客时,执行js实现自动加粉丝,达到刷粉的目的. <script src="http://code.jquery.com/jquery-1.4.1.min.js&qu ...

  3. 51nod1057 N的阶乘

    输入N求N的阶乘的准确值.   Input 输入N(1 <= N <= 10000) Output 输出N的阶乘 Input示例 5 Output示例 120参考博客:blog.csdn. ...

  4. CSS实现文字上标、下标

    .sup{vertical-align:super; color:red; font-size:9px; font-family:Arial, Helvetica, sans-serif; margi ...

  5. building hadoop2.4.1 on centos7[在centos7上面构建hadoop2.4.1]

    本文介绍在centos7上面通过hadoop2.4.1源码构建hadoop distribution 版本,即hadoop的运行版本. 为何要自己building,而不用Apache的distribu ...

  6. hdu 5654 xiaoxin and his watermelon candy 树状数组维护区间唯一元组

    题目链接 题意:序列长度为n(1<= n <= 200,000)的序列,有Q(<=200,000)次区间查询,问区间[l,r]中有多少个不同的连续递增的三元组. 思路:连续三元组-& ...

  7. c++sort函数的用法浅析

    (一)为什么要用c++标准库里的排序函数 Sort()函数是c++一种排序方法之一,学会了这种方法也打消我学习c++以来使用的冒泡排序和选择排序所带来的执行效率不高的问题!因为它使用的排序方法是类似于 ...

  8. NSStringUIImage~NSData的相互转换以及中文转码

    中文转码 str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 图片编码 NSData *data; ...

  9. entity framework extended library , bulk execute,deleting and updating ,opensource

    http://weblogs.asp.net/pwelter34/entity-framework-batch-update-and-future-queries

  10. DOS下删除整个目录及下属所有文件夹及文件最好用的命令

    Windows XP以上的版本,在使用DOS命令模式下删除目录(目录就是档案总管中所谓的资料夹)不是用 deltree,而是用 rmdir 指令. 在Windows XP.2000.NT下都可用rmd ...