CF A.Mishka and Contest【双指针/模拟】
【链接】: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【双指针/模拟】的更多相关文章
- Mishka and Contest(模拟水题)
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...
- 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 ...
- cf 443 D. Teams Formation](细节模拟题)
cf 443 D. Teams Formation(细节模拟题) 题意: 给出一个长为\(n\)的序列,重复\(m\)次形成一个新的序列,动态消除所有k个连续相同的数字,问最后会剩下多少个数(题目保证 ...
- Codeforces Round #543 (Div. 2) D 双指针 + 模拟
https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...
- 【CF 676B Pyramid of Glasses】模拟,递归
题目链接:http://codeforces.com/problemset/problem/676/B 题意:一个n层的平面酒杯金字塔,如图,每个杯子的容量相同.现在往最顶部的一个杯子倒 t 杯酒,求 ...
- BZOJ4837:[Lydsy1704月赛]LRU算法(双指针&模拟)
Description 小Q同学在学习操作系统中内存管理的一种页面置换算法,LRU(LeastRecentlyUsed)算法. 为了帮助小Q同学理解这种算法,你需要在这道题中实现这种算法,接下来简要地 ...
- (第六场)Singing Contest 【模拟】
题目链接:https://www.nowcoder.com/acm/contest/144/A 标题:A.Singing Contest | 时间限制:1 秒 | 内存限制:256M Jigglypu ...
- 坑爹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 ...
- cf B. Valera and Contest
http://codeforces.com/contest/369/problem/B 先对k个处理,先处理sk%k个为sk/k+1,如果sk/k==0,k个数都为sk/k:对与剩下的数也按照同样的方 ...
随机推荐
- ELK + Kafka + Filebeat
ELK + Kafka + Filebeat学习 https://blog.csdn.net/qq_21383435/article/details/79463832 https://blog.csd ...
- Codeforces Round #390 (Div. 2) E(bitset优化)
题意就是一个给出2个字符矩阵,然后进行匹配,输出每个位置的匹配的结果 (超出的部分循环处理) 一种做法是使用fft,比较难写,所以没有写 这里使用一个暴力的做法,考虑到一共只出现26个字符 所以使用一 ...
- [Leetcode] unique paths 独特路径
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- ionic安装遇到的一些问题
ionic = Cordova + Angular + ionic CSS // 安装(失败的话 Mac 尝试使用 sudo,Windows 尝试管理员身份运行 cmd)$ npm install - ...
- inflate
LayoutInflater是用 来找res/layout/下的xml布局文件,并且实例化 https://www.cnblogs.com/savagemorgan/p/3865831.html
- grub ubuntu启动
set root=(hd0,gpt10) 现在变为 gpt9 了 安装固态后.变成了 (hd1,gpt11) set prefix=(hd0,gpt10)/boot/grub insmod norma ...
- bzoj 2525 [Poi2011]Dynamite 二分+树形dp
[Poi2011]Dynamite Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 270 Solved: 138[Submit][Status][D ...
- hbase vs mongodb
1.HBase依赖于HDFS,HBase按照列族将数据存储在不同的hdfs文件中:MongoDB直接存储在本地磁盘中,MongoDB不分列,整个文档都存储在一个(或者说一组)文件中 (存储) 2.Mo ...
- ActiveMQ(2) ActiveMQ创建HelloWorld
启动ActiveMQ: 请参见:ActiveMQ(1) 初识ActiveMQ 创建Maven工程: pom文件: <project xmlns="http://maven.apache ...
- Linux 下打包报错:enospc (no space left on device)
昨天打了个包,早上发现很多页面js加载404,一查原来打包的min文件夹下是空的,打包出错了 Error code: enospc du -sh * rm -f 文件名称 rm -rf 目录名称 前端 ...