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:对与剩下的数也按照同样的方 ...
随机推荐
- group by 分组后 返回的是一个同属性的集合
group by 分组后 返回的是一个同属性的集合 我们可以遍历该集合
- Codeforces Round #553 F Sonya and Informatics
题目 题目大意 给定一个长为 $n$($2 \le n \le 100$)的01串 $S$ .对 $S$ 进行 $k$($1 \le k \le 10^9$)次操作:等概率地选取两个下标 $i, j$ ...
- Visual Studio调试之断点技巧篇补遗
原文链接地址:http://blog.csdn.net/Donjuan/article/details/4649372 讲完Visual Studio调试之断点技巧篇以后,翻翻以前看得一些资料和自己写 ...
- [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 ...
- taotao购物车
功能分析: 1.在用户不登陆的情况下也可以使用购物车,那么就需要把购物车信息放入cookie中. 2.可以把商品信息,存放到pojo中,然后序列化成json存入cookie中. 3.取商品信息可以从c ...
- es6+最佳入门实践(8)
8.Promise 8.1.什么是异步? 要理解异步,首先,从同步代码开始说 alert(1) alert(2) 像上面的代码,执行顺序是从上到下,先后弹出1和2,这种代码叫做同步代码 alert(0 ...
- 优化IDEA启动速度,快了好多。后面有什么优化点,会继续往里面添加
1.优化启动 修改bin/idea.exe.vmoptions文件如下: -Xms256m 初始堆大小-Xmx384m 最大堆大小 -XX:+UseParNewGC 使用并行收集算法 2. ...
- bzoj 1576: [Usaco2009 Jan]安全路经Travel——并查集+dijkstra
Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第i行包含一个数 ...
- apache工作模式
查看当前apache的工作模式 apachectl -l prefork模式 <IfModule prefork.c>StartServers 5MinSpareServers 5MaxS ...
- javascript学习3
javascript数据类型.函数传参 javascript语言核心:ECMAScript 定义js的语法:基本对象.数据类型 js的数据类型 typeof运算符 判断数据类型 字符串.数字.布尔. ...