70pts玄关求助,WA了3个
查看原帖
70pts玄关求助,WA了3个
753837
Ginka_楼主2024/6/14 14:35
#include<bits/stdc++.h>
using namespace std;
int n;
bool flag;
int mp[10][10];
int save[10][10][10];
int dx[2]={1,-1};
int xx[10],yy[10],bh[10];
int lxh[10][10];//横向连续
int lxs[10][10];//竖向连续
bool hx[10][10];
bool sx[10][10];
bool xiao[10][10];
void check()
{
	for(int i=1;i<=7;i++)
	{
		for(int j=1;j<=5;j++)
		{
			cout<<mp[i][j]<<" ";
		}
		cout<<endl;
	}
	return ;
}
void tidy()
{
	for(int j=1;j<=5;j++)
	{
		int wow=0;
		for(int i=7;i>=1;i--)
		{
			if(!mp[i][j]) wow++;
			else
			{
				if(!wow) continue;
				mp[i+wow][j]=mp[i][j];
				mp[i][j]=0;
			}
		}
	}
	return ;
}
bool delet()
{
	flag=false;
	for(int i=7;i>=1;i--)
	{
		for(int j=1;j<=5;j++)
		{
			if(j-1>=1&&j+1<=5&&mp[i][j]==mp[i][j-1]&&mp[i][j]==mp[i][j+1]&&mp[i][j])
			{
				xiao[i][j-1]=true;
				xiao[i][j+1]=true;
				xiao[i][j]=true;
				flag=true;
			}
			if(i-1>=1&&i+1<=7&&mp[i][j]==mp[i-1][j]&&mp[i][j]==mp[i+1][j]&&mp[i][j])
			{
				xiao[i-1][j]=true;
				xiao[i+1][j]=true;
				xiao[i][j]=true;
				flag=true;
			}
		}
	}
	if(!flag) return false;
	for(int i=7;i>=1;i--)
	{
		for(int j=1;j<=5;j++)
		{
			if(xiao[i][j])
			{
				xiao[i][j]=0;
				mp[i][j]=0;
			}
		}
	}
	return true;
}
bool pd()
{ 
	for(int i=7;i>=1;i--)
	{
		for(int j=1;j<=5;j++)
		{
			if(mp[i][j]) return false;
		}
	}
	return true;
}
void dfs(int step)
{
	if(pd())
	{
		for(int i=1;i<=n;i++)
		{
			cout<<xx[i]<<" "<<yy[i]<<" "<<bh[i]<<endl;
		}
		exit(0);
	}
	if(step>n)
	{
		return ;
	}
	for(int t=7;t>=1;t--)
	{
		for(int r=1;r<=5;r++)
		{
			save[step][t][r]=mp[t][r];
		}
	}
	for(int i=7;i>=1;i--)
	{
		for(int j=1;j<=5;j++)
		{
			if(mp[i][j])
			{
				{
					if(j+1<=5)
					{
						xx[step]=j-1;
						yy[step]=7-i;
						bh[step]=1;
						swap(mp[i][j+1],mp[i][j]);//方块交换
						tidy();//方块落下
						while(delet()) tidy();//方块删除
						dfs(step+1);
						for(int t=7;t>=1;t--)
							for(int r=1;r<=5;r++)
								mp[t][r]=save[step][t][r];
						xx[step]=-1;
						yy[step]=-1;
						bh[step]=-1;
					}
					if(j-1>=1&&mp[i][j-1]==0)
					{
						xx[step]=j-1;
						yy[step]=7-i;
						bh[step]=-1;
						swap(mp[i][j-1],mp[i][j]);//方块交换
						tidy();//方块落下
						while(delet()) tidy();//方块删除
						dfs(step+1);
						for(int t=7;t>=1;t--)
							for(int r=1;r<=5;r++)
								mp[t][r]=save[step][t][r];
						xx[step]=-1;
						yy[step]=-1;
						bh[step]=-1;
					}
				}
			}
		}
	}
	return ;
}
int main()
{
	cin>>n;
	for(int i=1;i<=5;i++)
	{
		int j=0;
		while(j==0||mp[8-j][i]!=0)
		{
			j++;
			cin>>mp[8-j][i];
		}
	}//\
	check();
	dfs(1);
	cout<<"-1";
	return 0;
}

从头改到尾还是没改对

坐标储存方式和答案要求不一样,我是以左上角为(1,1)存的,最后转换成题目要求的坐标

样例过了,没有被特殊数据hack,但是WA了三个

2024/6/14 14:35
加载中...