社区讨论

站外题求条

学术版参与者 2已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@mixzc4z3
此快照首次捕获于
2025/12/09 10:47
2 个月前
此快照最后确认于
2025/12/11 21:35
2 个月前
查看原帖
对于 30% 的数据 1N,Q1001\leq N,Q\leq100
对于 100% 的数据 1N,Q106,1xa,ya,xb,yb1061\leq N,Q\leq10^6,1\leq x_a,y_a,x_b,y_b\leq10^6
CPP
#include<bits/stdc++.h>
using namespace std;
const int inf=2e9;
#define fir first
#define sec second
#define mk make_pair
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define pq priority_queue
#define max(a,b) (a>b ? a : b )
#define min(a,b) (a<b ? a : b )
#define abs(x) (x<0 ? -x : x)
void read(int &x) {
	bool neg=false;
	x=0;
	char ch=0;
	while (ch<'0' || ch>'9') {
		if (ch=='-') neg=true;
		ch=getchar();
	}
	if (neg) {
		while (ch>='0' && ch<='9') {
			x=x*10+('0'-ch);
			ch=getchar();
		}
	} else {
		while (ch>='0' && ch< '9') {
			x=x*10+(ch-'0');
			ch=getchar();
		}
	}
}
void write(int x) {
	bool neg=false;
	if (x<0) {
		neg=true;
		putchar('-');
	}
	static int sta[40];
	int top=0;
	do {
		sta[top++]=x%10;
		x/=10;
	} while (x);
	if (neg) {
		while (top) putchar('0'-sta[--top]);
	} else {
		while (top) putchar('0'+sta[--top]);
	}
	return ;
}
const int dx[]={0,1,0,-1,0};
const int dy[]={0,0,1,0,-1};
int n;
int q;
int a[100009];
int b[100009];
int x,y,xx,yy;
//bool f[109][109];
struct node{
	int x,y;
};
bool bfs(int sx,int sy,int fx,int fy) {
	map<pii,bool> mp;
	queue<node> q;
	mp[mk(sx,sy)]=true;
	q.push({sx,sy});
	while (!q.empty()){
		int xxx=q.front().x,yyy=q.front().y;
		q.pop();
		if (xxx==fx && yyy==fy){
			return true;
		}
		for (int i=1;i<=4;i++){
			int nx=xxx+dx[i],ny=yyy+dy[i];
			if (nx<=n && ny<=n && nx>=1 && ny>=1 && !mp[mk(nx,ny)] && (a[nx]^b[ny])==0){
				mp[mk(nx,ny)]=true;
				q.push({nx,ny});
//				cout<<nx<<' '<<ny<<endl;
			}
		}
	}
	return false;
}
signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>q;
	for (int i=1; i<=n; i++) {
		cin>>a[i];
	}
	for (int i=1; i<=n; i++) {
		cin>>b[i];
	}
//	cout<<endl;
//	for (int i=1; i<=n; i++) {
//		for (int j=1; j<=n; j++) {
//			f[i][j]=a[i]^b[j];
//			cout<<f[i][j]<<' ';
//		}
//		cout<<endl;
//	}
	while (q--) {
		cin>>x>>y>>xx>>yy;
		if (bfs(x,y,xx,yy)){
			cout<<"YES"<<'\n';
		}
		else{
			cout<<"NO"<<'\n';
		}
	}
	return 0;
}

30pts,剩下的WA掉了
(悬一关)

回复

4 条回复,欢迎继续交流。

正在加载回复...