多校A层冲刺NOIP2024模拟赛01
构造字符串
咕咕咕
寻宝
咕咕咕
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int maxn=50009;
int n,m,k,q,tot,cnt,vis[32767];
int a[4]={1,-1,0,0};
int b[4]={0,0,-1,1};
map<int,short> mp[maxn];
queue<pair<int,int>> que;
vector<int> vec[32767];
void bfs(int sx,int sy){
mp[sx][sy]=++cnt;
que.push(make_pair(sx,sy));
while(que.size()){
int x=que.front().first;
int y=que.front().second;
que.pop();
for(int i=0;i<4;i++){
int tx=x+a[i],ty=y+b[i];
if(mp[tx][ty]) continue;
mp[tx][ty]=cnt;
que.push(make_pair(tx,ty));
}
}
}
bool dfs(int x,int goal,int rnd){
if(x==goal) return true;
if(!vec[x].size()) return false;
vis[x]=rnd;bool res=false;
for(auto to:vec[x]) if(vis[to]^rnd) res|=dfs(to,goal,rnd);
return res;
}
int main(){
freopen("treasure.in","r",stdin);
freopen("treasure.out","w",stdout);
scanf("%d%d%d%d",&n,&m,&k,&q);
int x1,y1,x2,y2;char c;mp[n+1][m+1]=-1;
for(int i=0;i<=n;i++) mp[i][0]=mp[i][m+1]=-1;
for(int j=0;j<=m;j++) mp[0][j]=mp[n+1][j]=-1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("\n%c",&c);
if(c=='#') mp[i][j]=-1;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(mp[i][j]) continue;
bfs(i,j);
}
}
while(k--){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
vec[mp[x1][y1]].push_back(mp[x2][y2]);
}
for(int i=1;i<=q;i++){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("%d\n",dfs(mp[x1][y1],mp[x2][y2],i));
}
return 0;
}
序列
咕咕咕
构树
咕咕咕
标签:sy,sx,int,衡中,多校,咕咕,que,NOIP2024 From: https://www.cnblogs.com/hypixel/p/18445827