P2327-[SCOI2005]扫雷
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef double db; 5 #define INF 0x3f3f3f3f 6 #define _for(i,a,b) for(int i = (a);i < b;i ++) 7 #define _rep(i,a,b) for(int i = (a);i > b;i --) 8 #define mod 20100403 9 10 inline ll read() 11 { 12 ll ans = 0; 13 char ch = getchar(), last = ' '; 14 while(!isdigit(ch)) last = ch, ch = getchar(); 15 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar(); 16 if(last == '-') ans = -ans; 17 return ans; 18 } 19 inline void write(ll x) 20 { 21 if(x < 0) x = -x, putchar('-'); 22 if(x >= 10) write(x / 10); 23 putchar(x % 10 + '0'); 24 } 25 int n; 26 int ans = 2; 27 int a[10003]; 28 int b[10003]; 29 void check() 30 { 31 _for(i,2,n+2) 32 { 33 b[i] = a[i-1]-b[i-1]-b[i-2]; 34 if(b[i]!=1&&b[i]) 35 { ans --;break;} 36 if(i==n+1&&b[i]) 37 { ans --;break;} 38 } 39 } 40 int main() 41 { 42 n = read(); 43 b[0] = 0; 44 _for(i,1,n+1) 45 a[i] = read(); 46 47 b[1] = 1; 48 check(); 49 b[1] = 0; 50 check(); 51 write(ans); 52 return 0; 53 }