您的位置:首页 > 其它

[noip2011day1T3][luogu1312]Mayan游戏

2018-03-31 19:30 239 查看
这是一道搜索题 貌似也不要很强的剪枝就能过

但是 我代码能力好弱啊..

一开始WA60了 然后改了后90了 依旧有一个点WA 开了O2后AC了???

原来O2是这样优化分数的吗????

于是去问dalao们 dalao表示最有可能是数组越界

于是我想了一下 好像有可能一行会读8个数 因为最后还有0..而我数组只开了7

于是我就去改数组 但是没有全改.. memcpy就光荣RE了

我改了好多好多次啊 什么WA TLE都出来了



#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[5][8],n,c[5][8],x[6],y[6],g[6],bo;

void down(int x,int y){
if (!y) return;
for(;y&&(!c[x][y-1]);c[x][y-1]=c[x][y],c[x][y]=0,y--);
}

void move(int x,int y,int g){
c[x][y]^=c[x+g][y]^=c[x][y]^=c[x+g][y];
for(int i=0;i<5;i++)
for(int j=0;j<7;j++)
if (c[i][j]) down(i,j);
int b[5][8];
memset(b,0,sizeof b);
while(1){
int pd=0;
memset(b,0,sizeof b);
for(int i=0;i<5;i++)
for(int j=2;j<7;j++)
if (c[i][j]&&c[i][j]==c[i][j-1]&&c[i][j]==c[i][j-2]) b[i][j]=b[i][j-1]=b[i][j-2]=pd=1;
for(int i=2;i<5;i++)
for(int j=0;j<7;j++)
if (c[i][j]&&c[i][j]==c[i-1][j]&&c[i][j]==c[i-2][j]) b[i][j]=b[i-1][j]=b[i-2][j]=pd=1;
if (!pd) break;
for(int i=0;i<5;i++)
for(int j=0;j<7;j++) if (b[i][j]) c[i][j]=0;
for(int i=0;i<5;i++)
for(int j=0;j<7;j++)
if (c[i][j]) down(i,j);

//   for(int i=0;i<5;i++) { for(int j=0;j<7;j++) cout<<c[i][j]<<' ';cout<<endl; }
}
}

int pd(){
for(int i=0;i<5;i++)
for(int j=0;j<7;j++) if (c[i][j]) return 1;
return 0;
}

void print(){
for(int i=1;i<=n;i++) cout<<x[i]<<' '<<y[i]<<' '<<g[i]<<endl;
}

void ymz(int k){
int sum=pd();
if (sum==0&&k>n) bo=1,print();
if (sum==0||k>n||bo) return;
int c0[5][8];
memcpy(c0,c,sizeof c);
for(int i=0;i<5;i++)
for(int j=0;j<7;j++){
if (!c[i][j]) continue;
if (i<4){
x[k]=i;y[k]=j;g[k]=1;
move(i,j,1);
ymz(k+1);
if (bo) return;
memcpy(c,c0,sizeof c);
}
if (i){
if (c[i-1][j]) continue;
x[k]=i;y[k]=j;g[k]=-1;
move(i,j,-1);
ymz(k+1);
if (bo) return;
memcpy(c,c0,sizeof c);
}
}
}

int main(){
cin>>n;
for(int i=0;i<5;i++){
cin>>a[i][0];
int j;
for(j=1;a[i][j-1];j++) cin>>a[i][j];
}
memcpy(c,a,sizeof a);
ymz(1);
if (!bo) printf("-1");
return 0;
}








貌似还有dalao对数据编程 太强辣!

#include <iostream>
#include <cstring>
using namespace std;
string s2="210010010",s3="110100100",s4="312232014134051413301535350443440",s5="401232404524611065365053550",s7="5202343044346204611443034661340",s8="5123220423102154403235052330",s9="512103145662023365506646055450",s10="5112340331235403553220553524200";
string a1,a2,a3,a4,a5,a6,a7,a8,a9,a10;
string n,c;
int main()
{
while(cin>>c)   n+=c;
if(n==s2)
cout<<"0 0 1"<<'\n'<<"4 0 -1"<<'\n';
else if(n==s3)
cout<<"3 0 -1"<<'\n';
else if(n==s4)
cout<<"2 0 1"<<'\n'<<"1 1 1"<<'\n'<<"3 4 -1"<<'\n';
else if(n==s5)
cout<<"2 4 1"<<'\n'<<"1 4 1"<<'\n'<<"1 2 1"<<'\n'<<"2 0 1"<<'\n';
else if(n==s7)
cout<<"1 1 -1"<<'\n'<<"2 4 1"<<'\n'<<"3 2 1"<<'\n'<<"3 6 1"<<'\n'<<"3 3 1"<<'\n';
else if(n==s8)
cout<<"1 0 1"<<'\n'<<"0 0 1"<<'\n'<<"2 2 1"<<'\n'<<"1 1 1"<<'\n'<<"3 0 1"<<'\n';
else if(n==s9)
cout<<"0 1 1"<<'\n'<<"1 1 1"<<'\n'<<"1 3 1"<<'\n'<<"1 2 1"<<'\n'<<"2 0 1"<<'\n';
else if(n==s10)
cout<<"0 4 1"<<'\n'<<"0 2 1"<<'\n'<<"1 3 1"<<'\n'<<"3 2 1"<<'\n'<<"3 0 1"<<'\n';
else
cout<<"-1"<<'\n';
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: