关闭

Light oj 1008 Fibsieve`s Fantabulous Birthday

176人阅读 评论(0) 收藏 举报
分类:
S - S
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<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	long long t,s,n,x,y;
	scanf("%lld",&t);
	int k=1;
	while(t--)
	{
		scanf("%lld",&s);
		n=sqrt(s);
		printf("Case %d: ",k++);
		if(n*n==s)
		{
			if(n%2==0)
			{
				printf("%lld 1\n",n);
				continue;
			}
			else
			{
				printf("1 %lld\n",n);
				continue;
			}
		}
		n++;
	    if(n*n-s<n)
	    {
	    	x=n;
	        y=n*n-s+1;
		}
		else
		{
			x=-n*n+2*n+s-1;
			y=n;
		 } 
		 if(n%2!=0)
		 swap(x,y);
		 printf("%lld %lld\n",x,y);
	}
}


0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

九度OJ 题目1008:最短路径问题

一题目描述: 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的。 输入: 输入n,m,点的编号是1...
  • lhyer
  • lhyer
  • 2015-08-08 19:44
  • 517

light oj 1005 不知道是个什么玩意

A rook is a piece used in the game of chess which is played on a board of square grids. A rook can o...
  • NineFailure
  • NineFailure
  • 2016-09-06 20:19
  • 160

九度oj-1008-最短路径问题

时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5636 解决:1814 题目描述: 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点...
  • u011514451
  • u011514451
  • 2014-09-01 21:30
  • 554

LightOJ 1138(求末尾零个数)

Description You task is to find minimal natural number N, so that N! contains exactly Q zeroes ...
  • zs120197
  • zs120197
  • 2016-08-18 20:14
  • 509

OnlineJudge 离线题库采集

过段时间要把以前的OJ换掉,我负责VirtualJudge的部分。需要用C与PHP写一个Linux下的VJudge。     在此之前,将以前写给自己学弟学妹用的OJ离线题库的采集程序改进了一下...
  • wchrt
  • wchrt
  • 2015-01-20 14:30
  • 811

AYITACM2016省赛第一周(深搜) E - A Knight's Journey骑士的旅行

E - A Knight's Journey Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d...
  • linyuxilu
  • linyuxilu
  • 2016-04-18 21:43
  • 339

lightoj1027(数学期望与概率)

题意: 你在一个迷宫里,面前有n扇们,每个门有一个数字k; 如果k为正数,则通过这扇门,走k分钟就能出去, 如果为负数,则通过这扇门走-k的分钟回到迷宫; 走每扇门概率一样.问走出迷宫所需时间...
  • yeyeyeguoguo
  • yeyeyeguoguo
  • 2015-06-08 20:50
  • 954

ACM1008玛雅历 剖析

原题如下:上周末,M.A. Ya教授对古老的玛雅有了一个重大发现。从一个古老的节绳(玛雅人用于记事的工具)中,教授发现玛雅人使用了一个一年有365天的叫做Haab的历法。这个Haab历法拥有19个月,...
  • errors5835
  • errors5835
  • 2017-03-25 13:58
  • 271

【light oj】树的直径

Farthest Nodes in a Tree Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & ...
  • idealistic
  • idealistic
  • 2016-08-02 15:29
  • 107

人脸识别之light_cnn

light_cnn出自2016 cvpr吴翔A Light CNN for Deep Face Representation with Noisy Labels, 优势在于一个很小的模型和一个非常不错...
  • qq_14845119
  • qq_14845119
  • 2017-02-23 18:03
  • 5586
    个人资料
    • 访问:158663次
    • 积分:8326
    • 等级:
    • 排名:第2809名
    • 原创:704篇
    • 转载:2篇
    • 译文:0篇
    • 评论:19条
    最新评论