P9690题解

题目传送门

思路

我们可以先不考虑停办年份,则第 y2y2 年就是第 y2y1+1y2-y1+1 次举办的。

考虑停办年份,则相差的是其中在 y1y1y2y2 之间的年份,所以只需要减去 y2\le y2 的停办年份数量即可。

注意事项

变量名不能定义为 y1,因为这是库函数名,所以会 CE!

代码

# include <bits/stdc++.h>
using namespace std;
int t, s, e, a[105], n, ans;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> t;
	while (t --) {
		cin >> s >> n;
		for (int i = 0; i < n; ++ i)
			cin >> a[i];
		cin >> e;
		ans = e - s + 1;
		for (int i = 0; i < n; ++ i)
			if (a[i] < e)
				-- ans;
			else
				break ;
		cout << ans << '\n';
	}
	return 0;
}
posted @ 2023-10-04 09:26  Vitamin_B  阅读(11)  评论(0)    收藏  举报  来源