救救孩子吧!样例AC,0分玄关!
  • 板块P3395 路障
  • 楼主yjjh
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/5 09:50
  • 上次更新2024/7/5 11:52:35
查看原帖
救救孩子吧!样例AC,0分玄关!
1036002
yjjh楼主2024/7/5 09:50
#include <bits/stdc++.h>
using namespace std;
const int N=1002;
int dt[N][N],n,lzs;
int lz[N][2];
int xx[4]={1,0,-1,0};
int yy[4]={0,1,0,-1};
std::queue<int>q1;
std::queue<int>q2;
inline int bbfs(int x,int y){
	for(int i=0;i<4;i++){
		if(x+xx[i]>=1&&x+xx[i]<=n&&y+yy[i]>=1&&y+yy[i]<=n&&dt[x+xx[i]][y+yy[i]]==0){
			if(x+xx[i]==n&&y+yy[i]==n)return 1;
			q1.push(x+xx[i]);q2.push(y+yy[i]);dt[x+xx[i]][y+yy[i]]=1;
		}
	}
	return 0;
}
inline int bfs(){
	for(int i=0;q1.size();i++){
		int t=bbfs(q1.front(),q2.front());
		if(t) return 1;
		q1.pop();q2.pop();
		dt[lz[i][0]][lz[i][1]]=1;
	}
	return 0;
}
int main(){
	int k;
	std::cin >>k;
	while(k--){
		while(q1.size())q1.pop(),q2.pop();
		memset(dt,0,sizeof dt);
		lzs=0;
		std::cin >>n;
		for(int i=0;i<n;i++)std::cin >>lz[lzs][0]>>lz[lzs++][1];
		q1.push(1);q2.push(1);
		if(bfs())std::cout <<"Yes"<<std::endl;
		else std::cout <<"No"<<std::endl;
	}
	return 0;
}
2024/7/5 09:50
加载中...