链接:

https://vjudge.net/problem/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. 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.

思路:

考虑每一个横竖区间,最大值为\(n^2\)的数列,直接先计算到属于区间,再细算。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector> using namespace std;
typedef long long LL;
const int INF = 1e9; const int MAXN = 1e6+10;
const int MOD = 1e9+7; int main()
{
int t, cnt = 0;
scanf("%d", &t);
while(t--)
{
LL s;
scanf("%lld", &s);
LL sq = sqrt(s);
if (sq*sq < s)
sq++;
LL sum = sq*sq;
LL x, y;
if (sq%2 == 1)
{
if (sum-s >= sq)
{
x = sq;
y = s-(sq-1)*(sq-1);
}
else
{
x = sum-s+1;
y = sq;
}
}
else
{
if (sum-s >= sq)
{
x = s-(sq-1)*(sq-1);
y = sq;
}
else
{
x = sq;
y = sum-s+1;
}
}
printf("Case %d: %lld %lld\n", ++cnt, x, y);
} return 0;
}

LightOJ-1008-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. HDU 4873 ZCC Loves Intersection(JAVA、大数、推公式)

    在一个D维空间,只有整点,点的每个维度的值是0~n-1 .现每秒生成D条线段,第i条线段与第i维度的轴平行.问D条线段的相交期望. 生成线段[a1,a2]的方法(假设该线段为第i条,即与第i维度的轴平 ...

  4. HDU 4870 Rating(概率、期望、推公式) && ZOJ 3415 Zhou Yu

    其实zoj 3415不是应该叫Yu Zhou吗...碰到ZOJ 3415之后用了第二个参考网址的方法去求通项,然后这次碰到4870不会搞.参考了chanme的,然后重新把周瑜跟排名都反复推导(不是推倒 ...

  5. HDU 5047 推公式+别样输出

    题意:给n个‘M'形,问最多能把平面分成多少区域 解法:推公式 : f(n) = 4n(4n+1)/2 - 9n + 1 = (8n+1)(n-1)+2 前面部分有可能超long long,所以要转化 ...

  6. CCF 201312-4 有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)

    问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...

  7. bjfu1211 推公式,筛素数

    题目是求fun(n)的值 fun(n)= Gcd(3)+Gcd(4)+…+Gcd(i)+…+Gcd(n).Gcd(n)=gcd(C[n][1],C[n][2],……,C[n][n-1])C[n][k] ...

  8. sgu495:概率dp / 推公式

    概率题..可以dp也可以推公式 抽象出来的题目大意: 有 n个小球,有放回的取m次  问 被取出来过的小球的个数的期望 dp维护两个状态 第 i 次取出的是 没有被取出来过的小球的 概率dp[i] 和 ...

  9. ASC(22)H(大数+推公式)

    High Speed Trains Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Su ...

  10. hdu_5810_Balls and Boxes(打表推公式)

    题目链接:hdu_5810_Balls and Boxes 题意: 如题,让你求那个公式的期望 题解: 打表找规律,然后推公式.这项技能必须得学会 #include<cstdio> #in ...

随机推荐

  1. 微信自研生产级paxos类库PhxPaxos实现原理介绍

    转载自:   http://mp.weixin.qq.com/s?__biz=MzI4NDMyNTU2Mw==&mid=2247483695&idx=1&sn=91ea4229 ...

  2. [转帖]重估BAT与华为的云上野心

    重估BAT与华为的云上野心 https://www.leiphone.com/news/201910/Z5aLhckqUjCNJ49o.html 本文作者:王刚 2019-10-11 16:19 导语 ...

  3. [转帖]Linux运维工程师的十个基本技能点

    Linux运维工程师的十个基本技能点 https://cloud.tencent.com/developer/article/1115068   本人是Linux运维工程师,对这方面有点心得,现在我说 ...

  4. Spring 中的统一异常处理

    在具体的SSM项目开发中,由于Controller层为处于请求处理的最顶层,再往上就是框架代码的.因此,肯定需要在Controller捕获所有异常,并且做适当处理,返回给前端一个友好的错误码. 不过, ...

  5. Java中XML的四种解析方式(一)

    XML是一种通用的数据交换格式,它的平台无关性.语言无关性.系统无关性给数据集成与交互带来了极大的方便.XML在不同的语言环境中解析的方式都是一样的,只不过实现的语法不同而已. XML文档以层级标签的 ...

  6. python学习-43 装饰器 -- 函数闭包2

    函数闭包为函数加上认证功能 1.登陆账号 user_dic ={'username':None,'login':False} def auth_func(func): def wrapper(*arg ...

  7. vue 使用vue-video-player播放hls格式视频

    安装 vue-video-player   在 “ devDependencies ” 中 安装  videojs-contrib-hls 在“ dependencies ”中   main.js 中 ...

  8. Questasim10.6c下载安装教程

    questasim作为modelsim的高级版,用着速度还是比modelsim爽很多,基本上所有操作指令都是和modelsim兼容的. 不同版本的vivado兼容的modelsim版本是不一样的,如果 ...

  9. [LeetCode] 234. 回文链表 ☆(翻转链表)

    描述 请判断一个链表是否为回文链表. 示例 1: 输入: 1->2输出: false示例 2: 输入: 1->2->2->1输出: true 进阶:你能否用 O(n) 时间复杂 ...

  10. 【fiddler】fiddler基础

    一.浏览器设置 一般情况下,fiddler会自动修改IE浏览器的设置,捕捉到IE浏览器的搜有通讯.其他浏览器需要手动设置 如chrome 打开chrome->设置->高级->系统-& ...