前言

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

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

题解

设一个" ┐"形为一层。

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

代码

#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. Django 调用支付宝接口

    目录 一  支付宝接口 二  视图函数 支付宝支付 正式环境:用营业执照,申请商户号,appid 测试环境:沙箱环境:https://openhome.alipay.com/platform/appD ...

  2. 7大python 深度学习框架的描述及优缺点绍

    Theano https://github.com/Theano/Theano 描述: Theano 是一个python库, 允许你定义, 优化并且有效地评估涉及到多维数组的数学表达式. 它与GPUs ...

  3. vmware中的虚拟linux配置多块网卡

    在使用vm上运行多个linux系统,来模拟LVS负载均衡实验中.需要在lvs服务器中设置两块网卡,发现可以在vm给虚拟机添加任意多个网卡. 方法: 不要启动Linux,在上面的菜单项中选择: “VM— ...

  4. 从入门到自闭之Python三大器--迭代器

    函数名的第一类对象(概述): 使用方式: 函数名可以当做值赋值给变量 def func(): print(1) print (func) #查看函数的内存地址 a = func print (a) # ...

  5. Django项目与mysql交互进行数据迁移时报错:AttributeError: 'str' object has no attribute 'decode'

    问题描述 Django项目启动,当我们执行命令 python manage.py makemigrations 出现如下错误: File , in last_executed_query query ...

  6. js汉字转换为拼音

    片段 1 片段 2 gistfile1.txt /* --- description: Pinyin, to get chinese pinyin from chinese. license: MIT ...

  7. 下载MySQL的rpm包安装MySQL

    cd /usr/local/src wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.27-1.el ...

  8. iOS 跳转系统设置界面

    iOS 跳转系统设置界面   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Pri ...

  9. JVM运行时的内存划分--JDK1.8

    对比JDK1.7,JDK1.8在运行时的内存分配上进行了调整.本篇对JDK1.8版本进行简要介绍. 先以一张图片描述运行时内存: 程序计数器 记录当前线程执行的字节码行号.如果执行的是native方法 ...

  10. 使用switchshow/supportshow命令确认Brocade交换机型号(转载)

    switchshow命令(或supportshow日志)中的switchType是以数字来代表不同的交换机型号,完整的对应表格如下: Switchtype EMC / Brocade名称 / 端口 / ...