本地 AC,提交 WA /kk

P1312 [NOIP2011 提高组] Mayan 游戏

```cpp #include<bits/stdc++.h> using namespace std; namespace _ { typedef long long ll; const ll N=10,inf=2147483647999999; const ll X[]={0,0,0,-1,1}; const ll Y[]={0,-1,1,0,0}; ll n,a[10][10],move[10][10],b[20]; void graph(ll t[10][10]) { printf("\n"); for(ll j=7;j>=1;j--) { for(ll i=1;i<=5;i++) printf("%lld ",t[i][j]); printf("\n"); } return; } void clone(ll t[10][10],ll q[10][10]) { for(ll i=1;i<=5;i++) for(ll j=1;j<=7;j++) t[i][j]=q[i][j]; return; } ll count(ll x,ll y,ll type,ll t[10][10],ll way) { ll cnt=0; while(t[x][y]==type) { if(x<1||x>5||y<1||y>7) break; cnt++;x+=X[way];y+=Y[way]; } return cnt; } void tag(ll x,ll y,ll type,ll t[10][10],ll v[10][10],ll way) { while(t[x][y]==type) { if(x<1||x>5||y<1||y>7) break; v[x][y]=1; x+=X[way];y+=Y[way]; } return; } ll clean(ll x,ll y,ll type,ll t[10][10],ll v[10][10]) { ll flag=0,cnt; cnt=count(x,y,type,t,1)+count(x,y,type,t,2); if(cnt>=4){ tag(x,y,type,t,v,1); tag(x,y,type,t,v,2); flag=1; } cnt=count(x,y,type,t,3)+count(x,y,type,t,4); if(cnt>=4){ tag(x,y,type,t,v,3); tag(x,y,type,t,v,4); flag=1; } return flag; } void fill(ll t[10][10],ll v[10][10]) { for(ll i=1;i<=5;i++) for(ll j=1;j<=7;j++) if(v[i][j]) t[i][j]=0; return; } ll clear(ll t[10][10]) { ll flag=0,v[10][10]; memset(v,0,sizeof(v)); for(ll i=1;i<=5;i++) for(ll j=1;j<=7;j++) { if(t[i][j]==0) continue; if(!clean(i,j,t[i][j],t,v)) continue; flag=1; } fill(t,v); return flag; } void fall(ll t[10][10]) { for(ll times=1;times<=7;times++) for(ll i=1;i<=5;i++) for(ll j=1;j<=7;j++) if(!t[i][j]) swap(t[i][j],t[i][j+1]); } ll check(ll t[10][10]) { for(ll i=1;i<=5;i++) for(ll j=1;j<=7;j++) if(t[i][j]) return 0; return 1; } ll cut(ll t[10][10]) { memset(b,0,sizeof(b)); for(ll i=1;i<=5;i++) for(ll j=1;j<=7;j++) if(t[i][j]>=1&&t[i][j]<=10) b[t[i][j]]++; for(ll i=1;i<=10;i++) if(b[i]==1||b[i]==2) return 1; return 0; } void print() { for(ll i=1;i<=n;i++) printf("%lld %lld %lld\n",move[i][0]-1,move[i][1]-1,move[i][2]); return; } void dfs(ll step,ll q[10][10]) { ll t[10][10],t2[10][10];clone(t,q); //graph(t);printf("step=%lld\n",step); if(cut(t)) return; if(step>n) { if(check(t)) print(),exit(0); return; } for(ll i=1;i<=5;i++) { for(ll j=1;j<=7;j++) { if(t[i][j]==0) continue; if(i<5) { clone(t2,t); swap(t2[i+1][j],t2[i][j]); move[step][0]=i; move[step][1]=j; move[step][2]=1; fall(t2); while(clear(t2)) fall(t2); dfs(step+1,t2); } if((i>1&&t[i-1][j]==0)||i==5) { clone(t2,t); swap(t2[i-1][j],t2[i][j]); move[step][0]=i; move[step][1]=j; move[step][2]=-1; fall(t2); while(clear(t2)) fall(t2); dfs(step+1,t2); } } } } void main() { ll j=0; scanf("%lld",&n); for(ll i=1;i<=5;) { scanf("%lld",&a[i][++j]); if(a[i][j]==0) {j=0;i++;} } dfs(1,a); printf("-1"); return; } } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); _::main(); return 0; } ```
by Yurchiu @ 2021-07-29 21:20:14


同时警示后人:**经查,数组开小了**。不知道为什么不够用。 别问,问就是玄学。 --- 下面是考古区域! 考古。
by Yurchiu @ 2021-07-29 22:32:56


--- 并非。是 dfs 中 t 数组没初始化而导致的奇奇怪怪的错误。所以记得初始化。 --- 继续考古! 考古。
by Yurchiu @ 2021-07-30 12:07:10


|