LightOJ-1008-Fibsieve`s Fantabulous Birthday(推公式)
链接:
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(推公式)的更多相关文章
- light oj 1008 - Fibsieve`s Fantabulous Birthday
1008 - Fibsieve`s Fantabulous Birthday PDF (English) Statistics Forum Time Limit: 0.5 second(s) Me ...
- [LOJ 1008] Fibsieve`s Fantabulous Birthday
A - Fibsieve`s Fantabulous Birthday Time Limit:500MS Memory Limit:32768KB 64bit IO Format:%l ...
- HDU 4873 ZCC Loves Intersection(JAVA、大数、推公式)
在一个D维空间,只有整点,点的每个维度的值是0~n-1 .现每秒生成D条线段,第i条线段与第i维度的轴平行.问D条线段的相交期望. 生成线段[a1,a2]的方法(假设该线段为第i条,即与第i维度的轴平 ...
- HDU 4870 Rating(概率、期望、推公式) && ZOJ 3415 Zhou Yu
其实zoj 3415不是应该叫Yu Zhou吗...碰到ZOJ 3415之后用了第二个参考网址的方法去求通项,然后这次碰到4870不会搞.参考了chanme的,然后重新把周瑜跟排名都反复推导(不是推倒 ...
- HDU 5047 推公式+别样输出
题意:给n个‘M'形,问最多能把平面分成多少区域 解法:推公式 : f(n) = 4n(4n+1)/2 - 9n + 1 = (8n+1)(n-1)+2 前面部分有可能超long long,所以要转化 ...
- CCF 201312-4 有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)
问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...
- 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] ...
- sgu495:概率dp / 推公式
概率题..可以dp也可以推公式 抽象出来的题目大意: 有 n个小球,有放回的取m次 问 被取出来过的小球的个数的期望 dp维护两个状态 第 i 次取出的是 没有被取出来过的小球的 概率dp[i] 和 ...
- ASC(22)H(大数+推公式)
High Speed Trains Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Su ...
- hdu_5810_Balls and Boxes(打表推公式)
题目链接:hdu_5810_Balls and Boxes 题意: 如题,让你求那个公式的期望 题解: 打表找规律,然后推公式.这项技能必须得学会 #include<cstdio> #in ...
随机推荐
- 记一次EFCore类型转换错误及解决方案
一 背景 今天在使用EntityFrameworkCore 查询的时候在调试的时候总是提示如下错误:Unable to cast object of type 'System.Data.SqlTyp ...
- 虚拟机性能监控与故障处理工具(深入理解java虚拟机三)
JDK自带的工具可以方便的帮助我们处理一些问题,包括查看JVM参数,分析内存变化,查看内存区域,查看线程等信息. 我们熟悉的有java.exe,javac.exe,javap.exe(偶尔用),jps ...
- struts笔记1
框架:所谓框架,就是把一些繁琐的重复性代码封装起来,使程序员在编码中把更多的精力放到业务需求的分析和理解上面 SHH:strust spring hibernate; SSM:springmvc sp ...
- 迅雷下载敏感资源 迅雷应版权方要求无法下载 μTorrent使用方法(六种方法,值得你看)(22)
1. 解决方案1 1.1 声明 此方法只适用于迅雷极速版,迅雷X不管用. 修改后下载有些磁力链接或种子,依然无反应.不是说该方法无效,而是有些种子资源不佳,很难下载,需要等半天才能连接上开始下载.如果 ...
- Python复习笔记01
(1)计算机常识 计算机:硬件(运算器,控制器,存储器,输入设备,输出设备)软件 (系统软件, 应用软件) 二进制 整数存储 文件单 位换算 1Byte = 8bit 1KB = 1024Byte 1 ...
- Linux 进程地址空间及原理
1.程序地址空间 首先,我们先看学c/c++时候学到的程序内存布局: 准确地说,程序地址空间其实就是进程的地址空间,实际就是pcb中的mm_struct. 接下来,我们用fork()演示一下 ...
- Linux下交换文件说明
vi写文件,没有保存就关闭,会自动生成一个后缀为.swp的交换文件(隐藏文件),保存了前面写的内容 先利用R恢复,在删除这个交换文件 涉及到的命令 ls –a rm .xxx.swap -rf
- Python学习路线2019升级版(课程大纲+视频教程+网盘资源下载)
2019最新Python全栈+人工智能学习路线升级版 全面涵盖前端.后端.爬虫.数据挖掘.人工智能等课程(课程大纲+视频教程+网盘资源下载)! 学习路线四大亮点: 1.人工智能三大主流框架全覆盖 2. ...
- 第1章 云端开发平台Salesforce CRM
1.1云计算平台 传统软件的开发往往耗资成千上万(甚至几百万)美元,有时需要几年的专业服务帮助建立和定制应用程序,而软件的业务问题往往由于其十分复杂或成本太高而无法触及.随着Internet的革新,改 ...
- 文件流FileStream的读写
1.FileStream文件流的概念: FileStream 类对文件系统上的文件进行读取.写入.打开和关闭操作,并对其他与文件相关的操作系统句柄进行操作,如管道.标准输入和标准输出.读写操作可以指定 ...