A. A Prank
Solved.
题意:
给出一串数字,每个数字的范围是$[1, 1000]$,并且这个序列是递增的,求最多擦除掉多少个数字,使得别人一看就知道缺的数字是什么。
思路:
显然,如果缺的这块数字的个数刚好等于右界 - 左界 + 1 那么就可以知道
还需要考虑数据范围,因为是$<= 1000 和 >= 1$ 那么对于两边的边界需要特殊考虑。
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define N 110 5 int n, a[N]; 6 7 int main() 8 { 9 while (scanf("%d", &n) != EOF) 10 { 11 for (int i = 1; i <= n; ++i) scanf("%d", a + i); 12 a[0] = 0; a[n + 1] = 1001; 13 int res = 0, tmp = 1; 14 for (int i = 1; i <= n + 1; ++i) 15 { 16 if (a[i] == a[i - 1] + 1) ++tmp; 17 else 18 { 19 res = max(res, tmp - 2); 20 tmp = 1; 21 } 22 } 23 res = max(res, tmp - 2); 24 printf("%d\n", res); 25 } 26 return 0; 27 }