zoukankan      html  css  js  c++  java
  • 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 } 
  • 相关阅读:
    查看数据库中指定用户下每个表占的实际空间大小
    数据库中查询列数据是否有重复
    oracle查看数据库的字符集
    【转】oracle数据库中varchar2陷阱
    cursor详解
    vs报算术运算溢出的错误
    count(1)比count(*)效率高
    基于NPOI的Execl导入导出例子
    day4-2数组及方法
    day4-1深入理解对象之创建对象
  • 原文地址:https://www.cnblogs.com/hsd-/p/5464465.html
Copyright © 2011-2022 走看看