看起来我做的和其他题解不一样
那就发一篇吧
首先本题情况看似无厘头,但是仔细观察,不难发现:
我们可以假设第一种情况,接着可以推出第二种
然后有了两个已知的后,第三个显而易见
如果你要问我怎么推出来的吗,我在里面说的的逻辑判断已经很明白了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #include<iostream> #include<cstdio> #include<cmath> #include<cstring>
using namespace std; int boom[10086]; int ans; int tj[10086]; int looker[10086]; int n; int pdf() { memset(looker,0,sizeof(looker)); for(int i=1;i<=n;i++) { if(tj[i]==1) { looker[i-1]++; looker[i]++; looker[i+1]++; } } for(int i=1;i<=n;i++) if(looker[i]!=boom[i]) return 0; return 1; } void getnext(int i)
{ if(i==2) { if(boom[i-1]==2) tj[i]=1; if(boom[i-1]==0) tj[i]=0; if(boom[i-1]==1&&tj[i-1]==1) tj[i]=0; if(boom[i-1]==1&&tj[i-1]==0) tj[i]=1; } else { if(boom[i-1]==0) tj[i]=0; if(boom[i-1]==3) tj[i]=1; if(tj[i-2]==0&&tj[i-1]==1&&boom[i-1]==2) tj[i]=1; if(tj[i-2]==0&&tj[i-1]==1&&boom[i-1]==1) tj[i]=0; if(tj[i-2]==0&&tj[i-1]==0&&boom[i-1]==1) tj[i]=1; if(tj[i-2]==1&&tj[i-1]==1&&boom[i-1]==2) tj[i]=0; if(tj[i-2]==1&&tj[i-1]==0&&boom[i-1]==2) tj[i]=1; if(tj[i-2]==1&&tj[i-1]==0&&boom[i-1]==1) tj[i]=0; } return ; } int pd(int f) { memset(tj,0,sizeof(tj)); tj[1]=f; for(int i=2;i<=n;i++) getnext(i); int bj=pdf(); return bj; } int main() { int i; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&boom[i]); ans+=pd(0); ans+=pd(1); printf("%d",ans); return 0; }
|