链接:

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;
}

最新文章

  1. windows和linux之间“/”, &quot;\\&quot;的区别
  2. mybatiGenerator
  3. ASP.NET 5 (vNext) 理解和概述
  4. [ruby on rails] 跟我学之(4)路由映射
  5. 利用VS编译libiconv库
  6. java 获取当前时间及年月日时分秒
  7. Kakfa揭秘 Day6 Consumer源码解密
  8. Struts 2的iterator标签来遍历一个含有双层List的嵌套
  9. codeforces 401D. Roman and Numbers 数位dp
  10. 授权给指定用户,使用navicat在其他ip都可以连接linux服务器上的mysql库
  11. 终端管理软件tmux
  12. p76泛函 有限维空间真子空间不可能在全空间稠密
  13. 继续JS之DOM对象二
  14. SpringMVC连接多数据源配置
  15. MySQL锁详解!(转载)
  16. Centos7编译4.7.2内核
  17. Android MediaPlayer播放音乐并实现进度条
  18. php备份mysql数据库
  19. OS X 与传统Unix的一点区别
  20. pylab.show()没有显示图形图像(python的matplotlib画图包)

热门文章

  1. 通过减少 IO 实现性能的优化
  2. Python尾递归优化
  3. Informix从一个表更新多选数据到另一个表
  4. springboot_2
  5. JavaScript (内置对象及方法)
  6. galera集群
  7. jQuery的显示和隐藏
  8. ajax跨域问题解决方案(jsonp的使用)
  9. Hystrix 熔断器
  10. Java 之 ObjectOutputStream 类