Light 1008

H - 字

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

Submit Status Practice LightOJ 1008

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<cstring>
#include<cmath>
#define LL long long
using namespace std;
LL n,m;
int main()
{
    LL y,x,k,t,s,l,r;
    LL cla;
    scanf("%lld",&cla);
    for(int gr=1; gr<=cla; gr++)
    {
        scanf("%lld",&n);
        printf("Case %lld: ",gr);
        s=sqrt(n);
        if(s*s==n)
        {
            if(!(s%2) )
                printf("%lld 1\n",s);
            else
                printf("1 %lld\n",s);
        }
        else
        {
            k=s+1;
            x=k*k-n;
            if(k%2==0)
            {
                if(x<k)
                    printf("%lld %lld\n",k,x+1);
                else printf("%lld %lld\n",2*k-x-1,k);
            }
            else
            {
                if(x<k)
                printf("%lld %lld\n",x+1,k);
                else printf("%lld %lld\n",k,2*k-1-x);
            }
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-12-15 01:53:19

Light 1008的相关文章

LightOJ 1008

1008 - Fibsieve`s Fantabulous Birthday 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 ches

1008. 数组元素循环右移问题 (20)

1008. 数组元素循环右移问题 (20) 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1--AN-1)变换为(AN-M -- AN-1 A0 A1--AN-M-1)(最后M个数循环移至最前面的M个位置).如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法? 输入格式:每个输入包含一个测试用例,第1行输入N ( 1<=N<=100).M(M>=0):第2行输入N个整数,之间用空格

light oj 1236 【大数分解】

给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,--em, 则结果为((1+2*e1)*(1+2*e2)--(1+2*em)+1)/2. //light oj 1236 大数分解素因子 #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <math.h> #include <ctype.h> #i

杭电女生赛1001 1002 1003 1005 1008 hdu6023 6024 6025 6027 6030

代码先贴这里 #include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm&quo

问题 1008: C语言程序设计教程(第三版)课后习题5.6

/******************************************************************** @file Main.cpp @date 2017-5-8 @author Zoro_Tiger @brief 问题 1008: C语言程序设计教程(第三版)课后习题5.6 http://www.dotcpp.com/oj/problem1008.html ***************************************************

1008 Envy

1008: Envy 时间限制: 1 Sec  内存限制: 128 MB提交: 288  解决: 61[提交][状态][讨论版] 题目描述 今年的 ACM 比赛推出了一个赛后的娱乐活动,所有参赛选手排成一排玩击鼓传花,关于击鼓传花的玩法是这样的:  数人或几十人围成圆圈坐下,其中一人拿花(或一小物件):另有一人背着大家或蒙眼击鼓(桌子.黑板或其他能发出声音的物体),鼓响时众人开始依次传花,至鼓停止为止.此时花在谁手中(或其座位前),谁就上台表演节目(多是唱歌.跳舞.说笑话:或回答问题.猜谜.按纸

编译或运行时可能会出现错误: Error:Error retrieving parent for item: No resource found that matches the given name “Theme.AppCompat.Light”

这个问题我在刚开始写"HelloWorld"时就遇到,以为是API版本太高,下载了常用的API 19.17--一系列的,后来还是有问题.就上网查了很多,遇到几篇不错的文章,记录下来,方便以后查看. No resource found that matches the given name 'Theme.AppCompat.Light 的完美解决方案  http://www.360doc.com/content/15/0316/15/9200790_455576135.shtml And

2016大连网络赛 1008 &amp; hdu5875 (优先队列+离线)=不确定暴力

题意:给你一个区间,求a_l%a_(l+1)%a_(l+2)%-%a_r 的值 分析:听说一个数在给定区间中只有不是很多的位置可一连续对它求模,所以想到一个比较暴力有可行的方法,猜想复杂度应该是nlogn.具体是这样的,从左到有枚举每个位置, L[]记录[1,r]中所有元素连续取模到r的值.一开始把a[1]加进优先队列pq,对于第二位置,若pq.top()>=a[i],取出并取模,然后更新对应的位置l的答案,并把取模后答案插入优先队列,然后处理有区间是2的所有询问.对于第i个位置,若pq.top

[2016-05-09][51nod][1008 N的阶乘 mod P]

时间:2016-05-09 21:21:54 星期一 题目编号:[2016-05-09][51nod][1008 N的阶乘 mod P] 题目大意:输入N和P(P为质数),求N! Mod P = ? (Mod 就是求模 %) 分析:直接算- #include<stdio.h> using namespace std; typedef long long ll; int main(){ ll n,p,ans = 1; scanf("%lld%lld",&n,&