Codeforces Round #350 (Div. 2) - B. Game of Robots (STL)
来源:互联网 发布:中国社会发展数据库 编辑:程序博客网 时间:2024/05/29 11:06
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until then-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
The first line contains two positive integers n andk (1 ≤ n ≤ 100 000,1 ≤ k ≤ min(2·109, n·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.
Print the k-th pronounced identifier (assume that the numeration starts from1).
2 21 2
1
4 510 4 18 3
4
水题:
题意:
有n 个机器人。
第一个机器人会报自己id,
第二个机器人会先报第一个,在报自己的
第三个 会报第一个报第二个 报第三个。
。
。
。
。
以此类推。
问第k个数是多少!
直接找到k 在那个sum 中 (其中sum[i]表示前1 + 2 + 3 。。。 + i)
然后做差输出第几个id 即可!
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const int maxn = 100000 + 10;ll sum[maxn];int a[maxn];void init(){ for (int i = 1; i <= maxn; ++i)sum[i] = sum[i-1] + i;}int main(){ init(); int n,k; while(scanf("%d%d",&n,&k) == 2){ for (int i = 1; i <= n; ++i)scanf("%d",&a[i]); int m = lower_bound(sum,sum+maxn,k) - sum; m = k - sum[m-1]; printf("%d\n",a[m]); } return 0;}
- Codeforces Round #350 (Div. 2) - B. Game of Robots (STL)
- Codeforces Round #350 (Div. 2) B. Game of Robots __ interesting
- Codeforce Round#350(Div. 2) 670B Game of Robots
- Codeforces Round #401 (Div. 2) B. Game of Credit Cards
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #428 (Div. 2) B. Game of the Rows
- Codeforces Round #401 (Div. 2) B. Game of Credit Cards(模拟)
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心)
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心+炒鸡多坑的模拟)
- Codeforces Round #428 (Div. 2) B. Game of the Rows (思维)
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心)
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心,补题)
- Codeforces Round #335 (Div. 2) B. Testing Robots 模拟
- Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)
- Codeforces Round #335 (Div. 2) B.Testing Robots
- Codeforces Round #335 (Div. 2) B. Testing Robots (模拟)
- Codeforces Round #335 (Div. 2) B. Testing Robots
- CodeForces - 670B Game of Robots (模拟)水
- 如何使用zeppelin实现大数据可视化
- ImportError: libcudart.so.7.0: cannot open shared object file: No such file or directory
- 每天一个linux命令-ln
- iOS开发之高级视图—— UITableView(三)读取plist文件
- Android中View(视图)绘制不同状态背景图片原理深入分析以及StateListDrawable使用详解
- Codeforces Round #350 (Div. 2) - B. Game of Robots (STL)
- Android 带你从源码的角度解析Scroller的滚动实现原理
- leetcode102:Binary Tree Level Order Traversal
- 又见拦截导弹
- BoneCP连接池配置参数详细说明
- DWR3.0 如何应用的简单介绍(有实例)
- 第十三周——虚析构函数
- plupload一个前端上传组件
- 命名ACL