AT_abc481_b.Polyline
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are N points on the xy-plane, numbered 1,2,…,N. The coordinates of point i are (i,Ai).
For i=1,2,…,N−1, connect point i and point i+1 with a line segment to form one polyline.
Find the number of points on this polyline (including its endpoints) whose y-coordinate is K.
Here, the constraints guarantee that the number of points satisfying the condition is finite.
在 xy-平面上有 N 个点,编号为 1,2,…,N。点 i 的坐标为 (i,Ai)。
对 i=1,2,…,N−1,用线段连接点 i 和点 i+1,从而构成一条折线。
求这条折线上(包括端点)纵坐标(即 y-坐标)恰好为 K 的点的个数。
此处,题目约束条件保证满足该条件的点的个数是有限的。
输入格式
The input is given from Standard Input in the following format:
N K
A1 A2 … AN
输入从标准输入中按以下格式给出:
N K
A1 A2 … AN
输出格式
Print the number of points on the polyline whose y-coordinate is K.
输出折线上 y 坐标为 K 的点的个数。
输入输出样例
输入#1
5 3 1 3 1 5 1
输出#1
3
输入#2
3 3 3 1 3
输出#2
2
输入#3
2 100 1 2
输出#3
0
说明/提示
Sample 1 Explanation:
As shown in the figure below, there are 3 points satisfying the condition: (2,3), (27,3), and (29,3).
Note that the point (2,3) is a common endpoint of the segment connecting points 1 and 2 and the segment connecting points 2 and 3, but it is counted as one point.

Sample 2 Explanation:
There are 2 points satisfying the condition: (1,3) and (3,3). Note that the points at the ends of the polyline are also counted.
Constraints
- 2≤N≤100
- 1≤Ai≤100 (1≤i≤N)
- Ai=Ai+1 (1≤i<N)
- 1≤K≤100
- All input values are integers.
样例 1 解释:
如下方图示所示,共有 3 个满足条件的点:(2,3)、(27,3) 和 (29,3)。
注意:点 (2,3) 同时是连接第 1 个点与第 2 个点的线段、以及连接第 2 个点与第 3 个点的线段的公共端点,但仍只计为一个点。

样例 2 解释:
共有 2 个满足条件的点:(1,3) 和 (3,3)。注意:折线两端的点也计入总数。
约束条件
- 2≤N≤100
- 1≤Ai≤100(1≤i≤N)
- Ai=Ai+1(1≤i<N)
- 1≤K≤100
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?