http://www.elijahqi.win/archives/3815
题目描述
Mishka started participating in a programming contest. There are n n problems in the contest. Mishka’s problem-solving skill is equal to k k .
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 k k . When Mishka solves the problem, it disappears from the list, so the length of the list decreases by 1 1 . Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve?
输入输出格式
输入格式:
The first line of input contains two integers n n and k k ( 1 \le n, k \le 100 1≤n,k≤100 ) — the number of problems in the contest and Mishka’s problem-solving skill.
The second line of input contains n n integers a_1, a_2, \dots, a_n a
1
,a
2
,…,a
n
( 1 \le a_i \le 100 1≤a
i
≤100 ), where a_i a
i
is the difficulty of the i i -th problem. The problems are given in order from the leftmost to the rightmost in the list.
输出格式:
Print one integer — the maximum number of problems Mishka can solve.
输入输出样例
输入样例#1:
8 4
4 2 3 1 5 1 6 4
输出样例#1:
5
输入样例#2:
5 2
3 1 2 1 3
输出样例#2:
0
输入样例#3:
5 100
12 34 55 43 21
输出样例#3:
5
说明
In the first example, Mishka can solve problems in the following order: [4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [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 5 5 .
In the second example, Mishka can’t solve any problem because the difficulties of problems from both ends are greater than k k .
In the third example, Mishka’s solving skill is so amazing that he can solve all the problems.
deque直接做
#include<bits/stdc++.h>
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0,f=1;char ch=gc();
while(!isdigit(ch)) {if (ch=='-') f=-1;ch=gc();}
while(isdigit(ch)) x=x*10+ch-'0',ch=gc();
return x*f;
}
deque<int> q;int n,k;
int main(){
// freopen("a.in","r",stdin);
n=read();k=read();
for (int i=1;i<=n;++i) q.push_back(read());
int cnt=0;
while(!q.empty()){
if(q.front()<=k) {q.pop_front(),++cnt;continue;}
if (q.back()<=k) {q.pop_back(),++cnt;continue;}break;
}printf("%d\n",cnt);
return 0;
}
Mishka参加了一个包含n个难度不等的问题的编程竞赛,他的解题能力为k。他从问题列表的两端按顺序选择并解决难度不超过k的问题,直到无法解决任何问题为止。输入包括问题数量n和Mishka的解题能力k,以及每个问题的难度。输出Mishka最多能解决多少个问题。例如,当n=8,k=4,问题难度为[4, 2, 3, 1, 5, 1, 6, 4]时,Mishka能解决5个问题。"
111949856,10544530,博哥零基础教你玩转ESP8266(六):ESP8266 Station模式详解,"['ESP8266开发', 'Wi-Fi连接', '物联网开发', '嵌入式硬件']

403

被折叠的 条评论
为什么被折叠?



