Input
4 5 10 4 18 3
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 the n-th robot says his identifier.
对于这组示例,我理解的是,10 10 4 10 4 18 10 4 18 3。所以k为5的时候,对应的第五个是4。
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
typedef long long LL;
typedef unsigned long long uLL;
using namespace std;
const int N=100010;
int a[N];
int main() {
LL n,m,i,k,l;
while (cin>>n>>k) {
for (i=1; i<=n; ++i) {
scanf ("%d",&a[i]);
}
l=0;
while (k>l) {
l++;
k-=l;//l递增,用k去反复减它。
}
(k) ?m=k:m=l;
cout<<a[m]<<endl;
}
return 0;
}