Mishka and Contest(模拟水题)
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka's problem-solving skill is equal to kk.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.
Mishka cannot solve a problem with difficulty greater than kk. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by 11. Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve?
Input
The first line of input contains two integers nn and kk (1≤n,k≤1001≤n,k≤100) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100), where aiaiis the difficulty of the ii-th problem. The problems are given in order from the leftmost to the rightmost in the list.
Output
Print one integer — the maximum number of problems Mishka can solve.
Examples
8 4
4 2 3 1 5 1 6 4
5
5 2
3 1 2 1 3
0
5 100
12 34 55 43 21
5
Note
In the first example, Mishka can solve problems in the following order: [4,2,3,1,5,1,6,4]→[2,3,1,5,1,6,4]→[2,3,1,5,1,6]→[3,1,5,1,6]→[1,5,1,6]→[5,1,6][4,2,3,1,5,1,6,4]→[2,3,1,5,1,6,4]→[2,3,1,5,1,6]→[3,1,5,1,6]→[1,5,1,6]→[5,1,6], so the number of solved problems will be equal to 55.
In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than kk.
In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
题目意思:一个人有n个问题需要去解决,他的解题能力为kk,只能解决难度比kk小的题目,解题的过程是从左边或者从右边开始解题,当他遇到解不出来的题的时候就会停止解题。
解题思路:使用一个双指针,一个从头到尾,一个从尾到头,分别遍历,记录比kk小的数的个数即可。
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n,m,flag,count;
int a[],i;
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
{
scanf("%d",&a[i]);
}
flag=;
count=;
for(i=;i<n;i++)
{
if(a[i]<=m)
{
count++;
}
else
{
break;
}
}
if(i>=n)
{
flag=;
}
if(!flag)
{
for(i=n-;i>=;i--)
{
if(a[i]<=m)
{
count++;
}
else
{
break;
}
}
}
printf("%d\n",count);
return ;
}
Mishka and Contest(模拟水题)的更多相关文章
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- POJ 2014:Flow Layout 模拟水题
Flow Layout Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3091 Accepted: 2148 Descr ...
- 模拟水题,查看二维数组是否有一列都为1(POJ2864)
题目链接:http://poj.org/problem?id=2864 题意:参照题目 哈哈哈,这个题discuss有翻译哦.水到我不想交了. #include <cstdio> #inc ...
- CodeForces 689A Mike and Cellphone (模拟+水题)
Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...
- UVA 10714 Ants 蚂蚁 贪心+模拟 水题
题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...
- B. Creating the Contest(水题)
直接水过 #include<iostream> #include<algorithm> using namespace std; ; int a[maxn]; int n, u ...
- Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...
- HDU4287-STL模拟水题
一场2012天津网络预选赛的题,签到题. 但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决. 一开始用的Char [] 后来改成了string,STL和string搭配起来 ...
- hdu 4891 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...
随机推荐
- Maven DebugConfiguration配置运行内存
-Xms256M -Xmx512M -XX:PermSize=256m -XX:MaxPermSize=512m
- tornado用户指引(四)------tornado协程使用和原理(三)
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/happyAnger6/article/details/51291221几种常用的协程方式: 1.回调 ...
- 移动端利用canvas画布简单实现刮刮乐效果
为了研究canvas一些属性简单实现的一个小效果 代码样式不太规范 随手写的 请问喷 初学者可以看下 css代码 <style> * { margin: 0; padding: 0; } ...
- sublime text 3安装 package control 插件的方法
自动安装的方法 - 快捷键ctrl+` 或者View->Show Console,输入如下代码 import urllib.request,os;pf='Package Control.sub ...
- 【Keil】Keil5的安装和破...
档案的话网上很多的,另外要看你开发的是哪种内核的芯片 如果是STC的,就安装C51 如果是STM的,就安装MDK 当然市面上有很多芯片的,我也没用过那么多种,这里也就不列举了 至于注册机,就是...恩 ...
- linux 下安装 Cisco Packet Tracer 7.11以及一些注意
https://blog.csdn.net/qq_35882901/article/details/77652571 https://linux.cn/article-5576-1.html 开启登录 ...
- 网络相关知识点:nginx相关概念
今天我们来介绍一下反向代理以及负载均衡相关内容: 反向代理: 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求, 然后将请求转发给内部网络上的服务器,并将从 ...
- geoserver中WMS服务详细说明
官方geoserver中WMS服务中几种操作的API的详细说明地址: http://docs.geoserver.org/stable/en/user/services/wms/reference.h ...
- P1488 肥猫的游戏
题目描述 野猫与胖子,合起来简称肥猫,是一个班的同学,他们也都是数学高手,所以经常在一起讨论数学问题也就不足为奇了.一次,野猫遇到了一道有趣的几何游戏题目,便拿给胖子看.游戏要求在一个有n个顶点凸多边 ...
- 北京Uber优步司机奖励政策(11月2日~11月8日)
用户组:优步北京人民优步A组(适用于11月2日-11月8日) 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不 ...