就是一直WA第二个点
by beretty @ 2018-04-24 18:28:07
不对,好像发错了,发的是没改前的。。
这个是一直90的。。
```
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
const int M = 10 ;
const int n = 5 ;
const int m = 7 ;
const int Fast = 19260817 ;
using namespace std;
int step,h[M],Cmax=-1;
int st[M][M];
int c[M+2];
bool f;
struct Answer{
int X,Y ;
int Opt;
}Ans[M];
bool vis[M][M];
inline int read(){
char c=getchar(); int x=0,w=1;
while(c>'9'||c<'0'){ if(c=='-') w=-1 ;c=getchar(); }
while(c>='0'&&c<='9'){ x=x*10+c-'0'; c=getchar() ; }
return x*w;
}
inline bool Candel(){
memset(vis,0,sizeof(vis));
bool Have = 0;
for(int i=1;i<=n;i++){
int num=0;
for(int j=2;j<=h[i];j++)
if(st[i][j]&&st[i][j]==st[i][j-1]){
++num;
if(num==2){
for(int k=j;k>=j-num;k--)
vis[i][k]=1;
Have = 1 ;
}
else if(num>2)
vis[i][j]=1;
}
else num=0;
}
for(int i=1;i<=m;i++){
int num=0;
for(int j=2;j<=n;j++)
if(st[j][i]&&st[j][i]==st[j-1][i]){
++num;
if(num==2){
for(int k=j;k>=j-num;k--)
vis[k][i]=1;
Have = 1 ;
}
else if(num>2)
vis[j][i]=1;
}
else num=0;
}
return Have ;
}
inline void Del(){
for(int i=1;i<=n;i++)
for(int j=1;j<=h[i];j++)
if(vis[i][j])
st[i][j]=0;
}
inline void Drop(){
for(int i=1;i<=n;i++)
for(int j=2;j<=h[i];j++)
if(st[i][j]&&!st[i][j-1]){
int Now = j-1 ;
while(!st[i][Now]&&Now>=1)
Now--;
st[i][Now+1]=st[i][j];
st[i][j]=0;
}
}
inline bool Check(){
for(int i=1;i<=n;i++)
for(int j=1;j<=h[i];j++)
if(st[i][j])
return false ;
return true ;
}
void Dfs(int now){
if(now==step+1){
if(Check())
f=1;
return ;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=h[i];j++){
if(st[i][j]){
for(int k=1;k>=0;k--)
if(k==1&&i!=n&&st[i][j]^st[i+1][j]){
int pre[M][M];
memcpy(pre,st,sizeof(st));
Ans[now].X=i-1;
Ans[now].Y=j-1;
Ans[now].Opt=1;
swap(st[i][j],st[i+1][j]);
Drop();
while(Candel()){
Del();
Drop();
}
Dfs(now+1);
if(f) return ;
memcpy(st,pre,sizeof(pre));
}
else if(k==0&&i!=1&&!st[i-1][j]){
int pre[M][M];
memcpy(pre,st,sizeof(st));
Ans[now].X=i-1;
Ans[now].Y=j-1;
Ans[now].Opt=-1;
swap(st[i][j],st[i-1][j]);
Drop();
while(Candel()){
Del();
Drop();
}
Dfs(now+1);
if(f) return ;
memcpy(st,pre,sizeof(pre));
}
}
else break;
}
}
int main(){
step = read();
for(int i=1;i<=n;i++){
int x = read();
while(x){
st[i][++h[i]]=x;
Cmax=max(Cmax,x);
x = read();
}
}
Dfs(1);
if(f)
for(int i=1;i<=step;i++)
printf("%d %d %d\n",Ans[i].X,Ans[i].Y,Ans[i].Opt);
else printf("-1\n");
return 0;
}
```
by beretty @ 2018-04-24 18:33:40
%%%
by Refun @ 2018-04-24 18:57:10
%%%
by Captain_Paul @ 2018-04-24 19:30:14