import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
/**
* P2327 [SCOI2005]扫雷
*/
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static int in() throws IOException {
in.nextToken();
return (int) in.nval;
}
static int n;
static int N = 10010;
static int[] f = new int[N];
static int[] a = new int[N];
public static void main(String[] args) throws IOException {
n = in();
for (int i = 1; i <= n; i++) {
a[i] = in();
}
int res = 0;
f[1] = 0;
if(check()) {
++res;
}
f[1] = 1;
if(check()) {
++res;
}
System.out.println(res);
}
public static boolean check() {
for (int i = 2; i <= n + 1; i++) {
f[i] = a[i - 1] - f[i - 1] - f[i - 2];
if(f[i] < 0) {
return false;
}
}
return f[n + 1] == 0;
}
}
这段代码我觉得是错误的,但是却能AC
hack数据:
6
2 2 2 2 2 2
这个样例输出结果是1,实际是0