P9690题解
思路
我们可以先不考虑停办年份,则第 年就是第 次举办的。
考虑停办年份,则相差的是其中在 与 之间的年份,所以只需要减去 的停办年份数量即可。
注意事项
变量名不能定义为 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;
}

浙公网安备 33010602011771号