前言

扫了一眼网上的题解,都是找规律。

估计就我一个蒟蒻在打二分。

题解

设一个" ┐"形为一层。

我们二分查找该数在那一层,然后就可以直接计算它的位置了。

代码

#include <cstdio>

int main(){
int T, cs = 0; scanf("%d", &T);
while (T--){
long long x; scanf("%lld", &x);
long long l = 1, r = 100000000, ans = 1;
while (l <= r){
long long mid = (l + r) / 2, tmp = (mid & 1) ? mid : mid - 1;
long long res = tmp * tmp + !(mid & 1);
if (res & 1)
res = res - mid * 2 + 2;
if (x >= res)
l = mid + 1, ans = mid;
else if (x < res)
r = mid - 1;
}
long long tmp = (ans & 1) ? ans : ans - 1;
long long res = tmp * tmp + !(ans & 1);
if (res & 1)
res = res - ans * 2 + 2;
long long lft = x - res; printf("Case %d: ", ++cs);
if (res & 1){
long long posx = ans, posy = 1;
if (lft < ans)
posy += lft;
else{
posy = ans; lft -= ans - 1;
posx -= lft;
}
printf("%lld %lld\n", posx, posy);
}
else{
long long posx = 1, posy = ans;
if (lft < ans)
posx += lft;
else{
posx = ans; lft -= ans - 1;
posy -= lft;
}
printf("%lld %lld\n", posx, posy);
}
}
return 0;
}

[LightOJ1008]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. [LOJ 1008] Fibsieve`s Fantabulous Birthday

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

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

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

  4. LightOJ Beginners Problems 部分题解

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

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

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

  6. lightoj刷题日记

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

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

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

  8. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  9. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

随机推荐

  1. flask 重定向详解

    from flask import Flask,request,redirect,url_for app = Flask(__name__) @app.route('/') def hello_wor ...

  2. Solrcloud+tomcat+zookeeper

    准备两台服务器,目录结构如下 主机名 IP地址 tomcat安装路径 zookeeper安装路径 solr安装路径 java安装路径 sht-sgmhadoopnn-01 172.16.101.55 ...

  3. nodejs 写服务器解决中文乱码问题

    nodejs 写服务器解决中文乱码问题:https://blog.csdn.net/worldmakewayfordream/article/details/77483423     本文链接:htt ...

  4. Gym 101466(完整)

    题目链接 :点击此处 ## Problem A 题意: 给你n个数,重定义两个数之间的加法不进位,求这些数中两个数相加的最大值和最小值. 题解: 字典树.我们首先将前i-1为放入字典树中,然后在查询第 ...

  5. 缓存---CDN(内容分发网络)

    4.CDN   内容分发网络(content distribution network,CDN)是一种互联的网络系统,它利用更靠近用户的服务器从而更快更可靠的将静态资源分发给用户. cdn主要有以下优 ...

  6. source与./执行的区别

    source与./执行的区别作用:使文件生效区别:1.source不需要文件有可执行(x)权限,而./需要文件有x权限,否则报错2.source执行是在当前shell中执行,./在当前shell的子s ...

  7. ubuntu安装selenium谷歌插件

    爬虫之selenium 安装与 chromedriver安装 今天学到一个有意思的插件,就是chromedriver,在爬虫的时候,如果网站反爬虫做的很好,自己又很想爬去里面的数据,那就可以用这个插件 ...

  8. js变量的作用域与函数作用域

    引自 1. 变量的作用域(var与let的区别) 在函数之外声明的变量,叫做全局变量,因为它可被当前文档中的任何其他代码所访问.在函数内部声明的变量,叫做局部变量,因为它只能在当前函数的内部访问. E ...

  9. 通过SEO可以做什么?

    1.做关键词排名,从而带来大量的客户卖产品和服务.很多大型机械厂家就是这么做的,显然SEO赚取了不少利润.     2.通过SEO带来大量流量,从而投放广告或者跟厂家合作买产品,比如流量站之类.    ...

  10. StanfordNLP for JAVA demo

    最近工作需要,研究学习 NLP ,但是 苦于官方文档太过纷繁,容易找不到重点,于是打算自己写一份学习线路 NLP 路线图 好博客韩小阳 斯坦福NLP公开课 统计学习方法 好博客 链接地址:https: ...