BZOJ1088 扫雷
水题,模拟。对于最后的方案数最多只会是2,想好久,又睡了一觉才想到这个,剩下的就好办了
1 #include <cstdio> 2 #include <cstring> 3 #include <vector> 4 #include <cmath> 5 #include <algorithm> 6 using namespace std; 7 #define lson l,m,rt<<1 8 #define rson m+1,r,rt<<1|1 9 const int maxn = 10005; 10 int a[maxn],vis[maxn]; 11 int n; 12 bool ok() 13 { 14 for(int i = 2;i<n;++i){ 15 if(a[i]==1){ 16 if(vis[i]==1&&vis[i-1]==1)return false; 17 if(vis[i]==1||vis[i-1]==1)vis[i+1] = 0; 18 else vis[i+1] = 1; 19 } 20 else if(a[i]==2){ 21 if(vis[i]==0&&vis[i-1]==0)return false; 22 if((vis[i]==1&&vis[i-1]==0)||(vis[i]==0&&vis[i-1]==1))vis[i+1] = 1; 23 else vis[i+1] = 0; 24 } 25 else if(a[i]==3){ 26 if(!(vis[i]==1&&vis[i-1]==1))return false; 27 vis[i+1] = 1; 28 } 29 else if(a[i]==0){ 30 if(vis[i]||vis[i-1])return false; 31 vis[i+1] = 0; 32 } 33 else return false; 34 } 35 if(vis[n-1]+vis[n]==a[n])return true; 36 else return false; 37 } 38 int main() 39 { 40 //freopen("in.txt","r",stdin); 41 scanf("%d",&n); 42 for(int i = 1;i<=n;++i)scanf("%d",&a[i]); 43 if(n==1){ 44 if(a[1]==1||a[1]==0)printf("1\n"); 45 else printf("0\n"); 46 return 0; 47 } 48 if(a[1]==3){printf("0\n");return 0;} 49 memset(vis,-1,sizeof(vis)); 50 int ans = 0; 51 if(a[1]==2){ 52 vis[1] = vis[2] = 1; 53 if(ok())ans++; 54 } 55 else if(a[1]==0){ 56 vis[1] = vis[2] = 0; 57 if(ok())ans++; 58 } 59 else if(a[1]==1){ 60 vis[1] = 1;vis[2] = 0; 61 if(ok())ans++; 62 memset(vis,-1,sizeof(vis)); 63 vis[1] = 0;vis[2] = 1; 64 if(ok())ans++; 65 } 66 printf("%d\n",ans); 67 return 0; 68 }
弱者究竟为何而战?!