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的更多相关文章

  1. [LOJ 1008] Fibsieve`s Fantabulous Birthday

    A - Fibsieve`s Fantabulous Birthday Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%l ...

  2. 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 ...

  3. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  4. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  5. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  6. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  7. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

  8. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

  9. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

随机推荐

  1. poj 1487 Single-Player Games

    主要考察表达式的解析和高斯消元!!! #include<iostream> #include<stdio.h> #include<algorithm> #inclu ...

  2. EntityFreamWork和Mvc 精品知识点

    定义了DbRepository<TEntity>:IRepository<TEntity> ,SimpleDbContext继承了DbContext, UnitOfWork:I ...

  3. Nginx、LVS及HAProxy负载均衡软件的优缺点详解

    http://www.csdn.net/article/2014-07-24/2820837

  4. Winform 数据验证

    http://blog.scosby.com/post/2010/02/11/Validation-in-Windows-Forms.aspx 总结:1. CancelEventArgs e ,调用e ...

  5. 锋利的JQuery-Jquery选择器

    1.css选择器 标签选择器:a{...} id选择器:#note{...} 类选择器:div.note{..}..dream{...} 群组选择器:td,p,div,a{...} 后代选择器: #l ...

  6. C#如何在派生类中不显示父类的一些属性以及TypeDescriptor使用

    public SonClass:FatherClass { 定义属性 .... } Type thisType = typeof(SonClass);方法一: PropertyInfo[] pis = ...

  7. Java版本的在指定目录及子目录下创建指定的文件

    和删除指定目录及子目录下名叫“xxx.txt”的所有文件一样,也是使用递归的方式实现的. 代码如下: public class Example826003 { private static FileO ...

  8. 完全用xml实现imageview点击换一张图片

    <ImageView android:layout_width="60dp" android:layout_height="60dp" android:b ...

  9. UVA 1324 The Largest Clique 最大团(强连通分量,变形)

    题意:给一个有向图,要求找出一些点,使得这些点中的任意点对,要么可以互通,要么单向可达. 思路:最低只要求单向可达即可,即a->b都可以算进去. 强连通分量内的点肯定是满足要求的,可以全选,但是 ...

  10. JDBC 与ODBC的区别

    一.ODBC(Open   DataBase   Connectivity   :  开放数据库连接)         ODBC  总体结构  应用程序    执行处理并调用odbc函数,提交sql语 ...