【链接】:CF/4892

【题意】:

一个人解决n个问题,这个问题的值比k小,

每次只能解决最左边的或者最右边的问题

解决了就消失了。问这个人能解决多少个问题。

【代码】:

#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define debug puts
#define setp cout << fixed << setprecision(3)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
const int N=3e5+5;
const int MOD=1e9+7;
const ll INF=1e18+8;
int n,k;
int a[N]; int main()
{
FAST_IO
while(cin>>n>>k)
{
int i=0;
int cnt=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int l=0,r=n-1;
while(1)
{
if( (a[l]>k && a[r]>k ) || i==n ) break;
if(a[l]<=k)
{
l++;
cnt++;
}
else if(a[r]<=k)
{
r--;
cnt++;
}
i++;
}
cout<<cnt<<endl;
}
}
/*
8 4
5 1 6 4
5 5 2
3 1 2 1 3
0
*/

CF A.Mishka and Contest【双指针/模拟】的更多相关文章

  1. Mishka and Contest(模拟水题)

    Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...

  2. CF 1009A Game Shopping 【双指针/模拟】

    Maxim wants to buy some games at the local game shop. There are n games in the shop, the i-th game c ...

  3. cf 443 D. Teams Formation](细节模拟题)

    cf 443 D. Teams Formation(细节模拟题) 题意: 给出一个长为\(n\)的序列,重复\(m\)次形成一个新的序列,动态消除所有k个连续相同的数字,问最后会剩下多少个数(题目保证 ...

  4. Codeforces Round #543 (Div. 2) D 双指针 + 模拟

    https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...

  5. 【CF 676B Pyramid of Glasses】模拟,递归

    题目链接:http://codeforces.com/problemset/problem/676/B 题意:一个n层的平面酒杯金字塔,如图,每个杯子的容量相同.现在往最顶部的一个杯子倒 t 杯酒,求 ...

  6. BZOJ4837:[Lydsy1704月赛]LRU算法(双指针&模拟)

    Description 小Q同学在学习操作系统中内存管理的一种页面置换算法,LRU(LeastRecentlyUsed)算法. 为了帮助小Q同学理解这种算法,你需要在这道题中实现这种算法,接下来简要地 ...

  7. (第六场)Singing Contest 【模拟】

    题目链接:https://www.nowcoder.com/acm/contest/144/A 标题:A.Singing Contest | 时间限制:1 秒 | 内存限制:256M Jigglypu ...

  8. 坑爹CF April Fools Day Contest题解

    H - A + B Strikes Back A + B is often used as an example of the easiest problem possible to show som ...

  9. cf B. Valera and Contest

    http://codeforces.com/contest/369/problem/B 先对k个处理,先处理sk%k个为sk/k+1,如果sk/k==0,k个数都为sk/k:对与剩下的数也按照同样的方 ...

随机推荐

  1. 有用的Java注解

    好处: 能够读懂别人的代码,特别是框架相关的代码: 让编程更加简洁,代码更加清晰. 使用自定义注解解决问题!! Java1.5版本引入. Java中的常见注解 @Override:告诉使用者及编译器, ...

  2. [BZOJ1283]序列

    Description 给出一个长度为n的正整数序列Ci,求一个子序列,使得原序列中任意长度为m的子串中被选出的元素不超过K(K,M<=100) 个,并且选出的元素之和最大. Input 第1行 ...

  3. [Leetcode] Convert sorted list to binary search tree 将排好的链表转成二叉搜索树

    ---恢复内容开始--- Given a singly linked list where elements are sorted in ascending order, convert it to ...

  4. C++——OOP面向对象理解

    从Rob Pike 的 Google+上的一个推看到了一篇叫<Understanding Object Oriented Programming>的文章,我先把这篇文章简述一下,然后再说说 ...

  5. oracle设置自动清理归档日志脚本

    设置定时自动清理归档日志脚本 root用户下 [root@localhost ~]# mkdir /nstg [root@localhost ~]# cd /nstg/ [root@localhost ...

  6. day10_plus

    刚才发奖哈哈哈 想不到被惨虐的我还能混个牌子哈哈哈好开心

  7. hdu1281(棋盘游戏,车的放置)

    Problem Description 给定一个n * m的棋盘,在棋盘里放尽量多的国际象棋中的车,使他们不能相互攻击 已知有些格子不能放置,问最多能放置多少个车 并计算出必须棋盘上的必须点. Inp ...

  8. Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency

    E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上 ...

  9. ionic安装遇到的一些问题

    ionic = Cordova + Angular + ionic CSS // 安装(失败的话 Mac 尝试使用 sudo,Windows 尝试管理员身份运行 cmd)$ npm install - ...

  10. Spring Boot(一)

    1.注解  @EnableAutoConfiguration 官方文档:The @EnableAutoConfiguration annotation is often placed on your ...