LightOJ1008---Fibsieve`s Fantabulous Birthday (规律)

Light OJ 1008- Fibsieve`s Fantabulous Birthday 直接模拟: #include #include using namespace std; int main() { int t; scanf("%d",&t); for(int ca=1;ca<=t;ca++) { long long n,x,r,c; scanf("%lld",&n); printf("Case %d: ",ca); x=sqrt(n); 阅读详情

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

Problem Setter: Muntasir Muzahid Chowdhury
Special Thanks: Jane Alam Jan (Dataset)

分别找到第一个>=s的和<=s的完全平方数,然后处理下细节即可

/*************************************************************************
        > File Name: LightOJ1008.cpp
        > Author: ALex
        > Mail: zchao1995@gmail.com
        > Created Time: 2015年06月04日 星期四 18时50分14秒
     ************************************************************************/

    #include <functional>
    #include <algorithm>
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <queue>
    #include <stack>
    #include <map>
    #include <bitset>
    #include <set>
    #include <vector>

    using namespace std;

    const double pi = acos(-1.0);
    const int inf = 0x3f3f3f3f;
    const double eps = 1e-15;
    typedef long long LL;
    typedef pair <int, int> PLL;

    int main() {
        int t, icase = 1;
        scanf("%d", &t);
        while (t--) {
            LL s;
            scanf("%lld", &s);
            int x = sqrt(s * 1.0);
            if ((LL)x * x == s) {
                if (x & 1) {
                    printf("Case %d: 1 %d\n", icase++, x);
                }
                else {
                    printf("Case %d: %d 1\n", icase++, x);
                }
                continue;
            }
            int i, j;
            if (x & 1) {
                if ((LL)x * x + x + 1 >= s) {
                    j = x + 1;
                    i = s - (LL)x * x;
                }
                else {
                    i = x + 1;
                    j =  x + 1 - (s - (LL)x * x - x - 1);
                }
            }
            else {
                if ((LL)x * x + x + 1 >= s) {
                    i = x + 1;
                    j = x + 1 - ((LL)x * x + x + 1 - s);
                }
                else {
                    j = x + 1;
                    i = x + 1 - (s - (LL)x * x - x - 1);
                }
            }
            printf("Case %d: %d %d\n", icase++, i, j);
        }
        return 0;
    }

Lightoj 1008 生日宴会 Description 某只同学在生日宴上得到了一个N×N玻璃棋盘,每个单元格都有灯。每一秒钟棋盘会有一个单元格被点亮然后熄灭。棋盘中的单元格将以图中所示的顺序点亮。每个单元格上标记的是它在第几秒被点亮。 第一秒棋格(1,1)将被点亮,第五秒棋格(3,1)将被点亮。 现在这只同学想知道在给定的时间哪个棋格将被点亮(时间将以秒为单位给出)。题目假设N足够大。 Inpu 阅读详情

相关推荐

LightOJ - 1008解题文档

LightOJ - 1008 以下为翻译 题意 也就是问每个数在哪一格 思路 同样是找规律 斜线:n*(n-1)+1 从最下面这一行和最左边这一列来看 偶数在偶数列/行,奇数在奇数列/行 奇数层数字大小从下到左(逆时针)顺序 偶数层数字大小从左到下(顺时针)顺序 因此判断时奇数层与偶数层应有一个相反的判断点 错误示范 #include<stdio.h> #include<math.h> int main() { long long s,n,sum,i=1,t; doubl

qq_52242579的博客 152

LightOJ - 1008

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.

Davisbook的博客 222

LightOJ 1008 Fibsieve`s Fantabulous Birthday规律

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

Tan_JX 319

lightoj 1008 - Fibsieve`s Fantabulous Birthday 【数学 找规律

1008 - Fibsieve`s Fantabulous Birthday PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Fibsieve had a fantabulous (yes, it's an a

世界很大 580

LightOJ1008 - Fibsieve`s Fantabulous Birthday规律

点击打开题目 1008 - Fibsieve`s Fantabulous Birthday     PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Fibsieve had a fantabulous

wyg1997 386

LightOj1008 - Fibsieve`s Fantabulous Birthday 数学规律

http://lightoj.com/volume_showproblem.php?problem=1008 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...

lanshan1111的博客 265

lightoj-1008 - Fibsieve`s Fantabulous Birthday【思维】【找规律

1008 - Fibsieve`s Fantabulous Birthday PDF (English) Statistics Forum Time Limit:0.5 second(s) Memory Limit:32 MB Fibsieve had a fantabulous (yes, it's an actual word) birthday party...

pxlsdz的博客 408

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

不二君 282

LightOJ 1008 - Fibsieve`s Fantabulous Birthday (规律)

1008 - Fibsieve`s Fantabulous Birthday PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Fibsieve

Chunzhen的博客 834

LightOJ-1008-Fibsieve`s Fantabulous Birthday [规律]

题目传送门题意:给定一个图表,求第n个数的坐标。思路:规律题,1 * 1的方阵最外层为1,2 * 2的方阵最外层为[2,4], 3 * 3的方阵最外层为[5,9],可知n*n的方阵最外层为[(n-1)^2+1,n^2]。可求出第N个数所在的最大方阵的行数和列数,根据行数的奇偶判断是先行后列还是先列后行增加,然后根据N与对角线的比较得到行号列号,#include <bits/stdc++.h>usin

裤头是叫裤头的裤头 413

Lightoj1008——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

Beyond the Sora 718

【ACM】LightOJ - 1008 Fibsieve`s Fantabulous Birthday (找规律,找...)

https://vjudge.net/problem/LightOJ-1008 题目很好理解,第一行表示测试样例的个数,接下来输入一个大于等于1的数,按照格式输出这个数的坐标     蓝色的是 奇数的平方; 红色的是 偶数的平方; 黄色的是对角线:对角线满足规律 n * (n - 1)+ 1,其中 n 为行(列)数; 需要分情况讨论,正好是平方数,n开方后是奇数还偶数,比斜对角线上...

( :3 ) 290

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

Description 某只同学在生日宴上得到了一个N×N玻璃棋盘,每个单元格都有灯。每一秒钟棋盘会有一个单元格被点亮然后熄灭。棋盘中的单元格将以图中所示的顺序点亮。每个单元格上标记的是它在第几秒被点亮。 第一秒棋格(1,1)将被点亮,第五秒棋格(3,1)将被点亮。 现在这只同学想知道在给定的时间哪个棋格将被点亮(时间将以秒为单位给出)。题目假设N足够大。 Inpu...

weixin_30872867的博客 84

LightOJ - 1008--Fibsieve`s Fantabulous Birthday (找规律

题目描述:按照题目所给的顺序填充排列自然数,给你一个n,输出n在这个特殊序列中所在的坐标。 思路:一道找规律的题,数据的排列可以类似的看做一个蛇形路段,每一个对勾的拐点就是一个完全平方数,并且开方数刚好就是偶数行的横向坐标或者奇数行的纵坐标,然后再次观察可找到每个对勾的拐角点(也就是说图形的对角线就是本行的完全平方数减去上一行的行数就行),最后根据对角线的位置可以确定n的另外一个坐标。(估计你肯...

weixin_30640291的博客 103

大一集训题i题生日聚会lightoj-1008 - Fibsieve`s Fantabulous Birthday

大一集训题i题生日聚会lightoj-1008 - Fibsieve`s Fantabulous Birthday **大一集训题i题生日聚会lightoj-1008 - Fibsieves Fantabulous Birthday**## 大一集训题i题生日聚会lightoj-1008 - Fibsieves Fantabulous Birthday Fibsieve had a fantabulous (yes, it’s an actual word) birthday party this year

K1_KCY的博客 334

LightOJ1008 Fibsieve`s Fantabulous Birthday

题目链接: http://lightoj.com/volume_showproblem.php?problem=1008 1008 - Fibsieve`s Fantabulous Birthday     PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB ...

Source_Roc 324

Light OJ - 1008- Fibsieve`s Fantabulous Birthday 暑期小练习

Light OJ - 1008- Fibsieve`s Fantabulous Birthday S - S Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Fibsieve had afantabulous (yes, it's an

Shyazhut 461
上一篇: POJ2407---Relatives(求单个数的欧拉函数)
下一篇: LightOJ1009---Back to Underworld (bfs染色)
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值