• Codeforces Round #350 (Div. 2) B


    B. Game of Robots
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 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 the n-th robot says his identifier.

    Your task is to determine the k-th identifier to be pronounced.

    Input

    The first line contains two positive integers n and k (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.

    Output

    Print the k-th pronounced identifier (assume that the numeration starts from 1).

    Examples
    Input
    2 2
    1 2
    Output
    1
    Input
    4 5
    10 4 18 3
    Output
    4
    Note

    In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.

    In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.

    题意:给你n个数 例如 i1 i2 i3 ....in  按要求排列   形如i1 (i1 i2)  (i1 i2 i3).....(i1 i2 i3 i4...in)  要求输出该序列的第k个值

    题解:求1~n的前缀和

            for循环判断k的位置  输出相应的值

     1 #include<bits/stdc++.h>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdio>
     5 #include<queue>
     6 #include<stack>
     7 #include<map> 
     8 #define ll __int64
     9 #define pi acos(-1.0)
    10 using namespace std;
    11 ll n,k;
    12 ll a[100005];
    13 ll sum[100005];
    14 ll ans;
    15 int  main()
    16 {
    17     scanf("%I64d %I64d",&n,&k);
    18     sum[0]=0;
    19     for(int i=1;i<=n;i++)
    20      {
    21      scanf("%d",&a[i]);
    22      sum[i]=sum[i-1]+i;
    23      }
    24     for(int i=1;i<=n;i++)
    25     {
    26         if(k<=sum[i])
    27          {
    28              ans=i;
    29              break;
    30          }
    31     }
    32     printf("%I64d
    ",a[(k-sum[ans-1])]);
    33     return 0; 
    34 } 
  • 相关阅读:
    交通部道路运输车辆卫星定位系统部标JTT808、809、796标准大全
    linux下如何源码编译安装vim
    Ubuntu如何重新启动tftp服务
    Ubuntu如何自定义tftp服务根目录
    git如何撤销git add操作?
    如何使两台主机间的不同网段互通?
    debian下如何源码安装tmux
    mysql插入数据自动生成主键uuid
    mysql的 UUID的生成方式
    MySQL SQL语句 生成32位 UUID
  • 原文地址:https://www.cnblogs.com/hsd-/p/5464465.html
Copyright © 2020-2023  润新知