【CodeForces 622A】Infinite Sequence
题意
一个序列是, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5....这样排的,求第n个是什么数字。
分析
第n个位置属于1到k,求出k,然后n-i*(i-1)/2就是答案了。
方法1:可以枚举k为i,当i*(i+1)/2大于等于n时,k就是i了。
方法2:先让k=floor(sqrt(2*n)),如果k*(k+1)/2<n,那正确的k应该+1。
代码
方法1的写法1:
#include<cstdio>
int main()
{
long long n,i;
scanf("%lld",&n);
for(i=; i<=1e8; i++)
{
if(i*(i+)/>=n) break;
}
printf("%lld",n-i*(i-)/);
return ;
}
方法1的写法2:
#include<cstdio>
int main()
{
long long n,i;
scanf("%lld",&n);
i=;
while(i*(i+)/<n)
{
i++;
}
printf("%lld",n-i*(i-)/);
return ;
}
方法2
#include<cstdio>
#include<cmath> int main()
{
long long n,k; scanf("%lld",&n);
k=floor(sqrt(*n));
if (k*(k+)/<n)
{
k++;
}
printf("%lld",n-k*(k-)/);
return ;
}
【CodeForces 622A】Infinite Sequence的更多相关文章
- 【codeforces 196B】Infinite Maze
[题目链接]:http://codeforces.com/problemset/problem/196/B [题意] 给你一个n*m的棋盘; 然后你能够无限复制这个棋盘; 在这个棋盘上你有一个起点s; ...
- 【codeforces 466D】Increase Sequence
[题目链接]:http://codeforces.com/problemset/problem/466/D [题意] 给你n个数字; 让你选择若干个区间; 且这些区间[li,ri]; 左端点不能一样; ...
- 【codeforces 602D】Lipshitz Sequence
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- codeforces 622A A. Infinite Sequence (二分)
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【codeforces 623E】 Transforming Sequence
http://codeforces.com/problemset/problem/623/E (题目链接) 题意 长度为${n}$的满足前缀按位或为单调递增的${k}$位序列.要求每个位置为${[1, ...
- 【arc071f】Infinite Sequence(动态规划)
[arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【47.40%】【codeforces 743B】Chloe and the sequence
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 438D】The Child and Sequence
[原题题面]传送门 [大致题意] 给定一个长度为n的非负整数序列a,你需要支持以下操作: 1:给定l,r,输出a[l]+a[l+1]+…+a[r]. 2:给定l,r,x,将a[l],a[l+1],…, ...
随机推荐
- 怎么通过js获取上传的图片信息(临时保存路径,名称,大小)然后通过ajax传递给后端?
今天在论坛上看到这样一个问题,有必要编辑搜集下. 问题描述:怎么通过js获取上传的图片信息(临时保存路径,名称,大小)然后通过ajax传递给后端 题主用jquery接收 <input name= ...
- [3D跑酷] AudioManager
Unity音频管理 游戏中的声音管理最常用的组件莫过于AudioSource和AudioClip,我的做法是建立是一个AudioManager类(单例类)管理各个音频,谈一下我的经验: 函数列表 St ...
- QTP和WinRunner区别
QTP,全称为Quick Test Professional,它与WinRunner同为MI公司开发的功能强大的功能测试工具.从时间上来看,WinRunner在1995年便已经推出,远早于QTP,而Q ...
- [转] Android实时抓包分析 : 善用adb调试桥
Android实时抓包分析 : 善用adb调试桥 谈到android网络抓包,很多人都能想到牛逼轰轰的神器tcpdump.方法就是在android机器上面安装tcpdump,然后通过-w参数把抓包 ...
- AndroidStudio权威教程 AS添加第三方库的6种方式(Jar module so等)
点击项目设置按钮 依次选择 App > Dependencies 1. 直接搜索法 依次选择 + > Library dependency 这里的搜索一定要是全名的,不然搜不到哦 下图所表 ...
- U3D rootMotion
Body Transform The Body Transform is the mass center of the character. It is used in Mecanim's retar ...
- 在Sql Server 中使用正则表达式
CREATE FUNCTION dbo.find_regular_expression ( ), --需要匹配的源字符串 ), --正则表达式 --是否区分大小写,默认为false ) RETURNS ...
- JS第一个动画
描述:让页面中的一个盒子平稳向右移动到指定位置 <div id="div1"> <div> JS代码实现 <script type="tex ...
- C#文件和文件文件夹按时间、名称排序-顺序与倒序
对于文件和文件夹有多种排序方式,常用的就是按创建或修改时间.按文件名排序.在 C# 中,按时间和文件名排序都十分简单,用数组提供的排序方法 Array.Sort() 一行代码就可以搞定,当然也可以用常 ...
- vi 命令 用法
一.Unix编辑器概述 编辑器是使用计算机的重要工具之一,在各种操作系统中,编辑器都是必不可少的部件.Unix及其相似的ix 操作系统系列中,为方便各种用户在各个不同的环境中使用,提供了一系列的ex编 ...