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 } 
  • 相关阅读:
    shell脚本计算斐波那契数列
    SQL查询出某字段不等于某值的行(其中有为NULL的字段)
    如何修改和关闭1433端口
    SqlServer 数据库日志无法收缩处理过程
    人生的抉择—aspx、ashx、asmx文件处理请求效率比较
    HTTP 错误 500.21
    如何使用快照来初始化化请求订阅
    怎么改svn的登陆账号
    更换用installshield打包生成exe文件的图标【转】
    win10下怎么在桌面创建IIS快捷方式
  • 原文地址:https://www.cnblogs.com/hsd-/p/5464465.html
Copyright © 2011-2022 走看看