CodeForces 670B Game of Robots

简单题。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c=getchar(); x=0;
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) {x=x*10+c-‘0‘; c=getchar();}
}

int n,k;
int a[100010];

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int L=1,R=n,pos;
    while(L<=R)
    {
        int mid=(L+R)/2;
        LL num=(LL)(1+mid)*(LL)mid/(LL)2;
        if(num>=(LL)k) R=mid-1,pos=mid;
        else L=mid+1;
    }

    k=k-(1+pos-1)*(pos-1)/2;
    printf("%d\n",a[k]);

    return 0;
}
时间: 2024-08-04 08:29:44

CodeForces 670B Game of Robots的相关文章

【解题报告】Codeforces Round #350 (Div. 2)

题目链接 A.Holidays(Codeforces 670A) 思路 首先,若 7 能整除 n 的话,最小假期天数 m1 与最大假期天数 m2 都等于 2×n7 ."整除"提示我们可以根据 n 除以 7 的余数来分类: 余数为 0 , m1=m2=2×n7 . 余数为 1 ,考虑多出来的那天是不是周末, m1=2×n7,m2=2×n7+1 . 余数为 6 ,考虑多出来的6天中必然有周末,考虑有1天周末还是2天周末, m1=2×n7+1,m2=2×n7+2 . 其它余数,考虑多出来的那

codeforces ~ 1004 C Sonya and Robots (dp)

C. Sonya and Robots time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya ha

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) A. Contest for Robots(思维题)

Polycarp is preparing the first programming contest for robots. There are nn problems in it, and a lot of robots are going to participate in it. Each robot solving the problem ii gets pipi points, and the score of each robot in the competition is cal

CodeForces 606B Testing Robots

模拟,题意看了一小时 /* *********************************************** Author :Zhou Zhentao Email :[email protected] Created Time :2015/12/15 13:19:28 File Name :main.cpp ************************************************ */ #include <stdio.h> #include <str

Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Robots are becoming more and more popular. They are used nowadays not only in manufacturing plants, but also at home. One programmer wit

【题解】CF24D Broken Robots(收敛性)

[题解]CF24D Broken Robots http://codeforces.com/problemset/problem/24/D 解1 获得一个比较显然的转移式子 \(dp(i,j)\)代表在\((i,j)\)坐标需要期望的走的次数 \[ dp(i,j)=0.25(1+dp(i-1,j)+dp(i,j-1)+dp(i,j+1)) \] 然而我们可以发现这个式子不满足无后效性..也找不到一种合适的顺序DP. 我们发现可以高斯消元,但是\(O(n^4)\)的复杂度我们接受不了. 式子里面的

Codeforces Round #634 (Div. 3) 补题

A. Candies and Two Sisters 签到题,直接输出即可 代码 #include<bits/stdc++.h> #define INF 0x3f3f3f3f typedef long long ll; using namespace std; inline void read(int &p) { p=0;int flag=1;char c=getchar(); while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();} w

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b