还有如此水题。。。以前真的太怕bzoj了QAQ

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(i=l;i<=r;i++)
 3 #define dec(i,l,r) for(i=l;i>=r;i--)
 4 #define inf 1e9
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define NM 10000+5
 7 using namespace std;
 8 int n,i,t,a[NM],s;
 9 bool b[NM];
10 int main(){
11     scanf("%d",&n);
12     inc(i,1,n)scanf("%d",&a[i]);
13     b[1]++;
14     inc(i,1,n){
15         t=a[i];
16         if(b[i-1])t--;
17         if(b[i])t--;
18         if(t)b[i+1]++;
19         if(t>1||t<0){
20             t=-1;
21             break;
22         }
23     }
24     if(t!=-1&&!b[n+1])s++;
25     mem(b);
26     b[1]=false;
27     inc(i,1,n){
28         t=a[i];
29         if(b[i-1])t--;
30         if(b[i])t--;
31         if(t)b[i+1]++;
32         if(t>1||t<0){
33             t=-1;
34             break;
35         }
36     }
37     if(t!=-1&&!b[n+1])s++;
38     printf("%d",s);
39     return 0;
40 }
View Code

 

posted on 2015-08-11 20:20  onlyRP  阅读(171)  评论(2编辑  收藏  举报