社区讨论
大佬26pt求调
P1825[USACO11OPEN] Corn Maze S参与者 1已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lo1j93sl
- 此快照首次捕获于
- 2023/10/22 21:57 2 年前
- 此快照最后确认于
- 2023/11/02 22:50 2 年前
CPP
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
char map[305][205];
bool vis[305][305];
int ans_x=0,ans_y=0;
int start_x,start_y;
int point;
int n,m;
struct place{
int x,y;
};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
bool check(int x,int y){
if(map[x][y]!='#' && vis[x][y] == 0 && x>=1 && y>=1 && x<=n &&y<=m){
return 1;
}
return 0;
}
bool check_door(int x,int y){
if(map[x][y]>='A' && map[x][y]<='Z'){
return 1;
}
return 0;
}
place next_door(int x,int y){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i!=x && j!=y && map[i][j]==map[x][y]){
place p;
p.x=i;
p.y=j;
return p;
}
}
}
}
struct node{
int x,y;
int step;
}cow;
queue <node> q;
void bfs(int x,int y){
node tmp;
tmp.x=x;
tmp.y=y;
tmp.step=0;
q.push(tmp);
while(!q.empty()){
cow=q.front();
q.pop();
if(map[cow.x][cow.y]=='='){
point=cow.step;
return;
}
if(check_door(cow.x,cow.y)){
place next=next_door(cow.x,cow.y);
cow.x=next.x;
cow.y=next.y;
vis[next.x][next.y]=1;
}
for(int i=0;i<4;i++){
int xx=cow.x+dx[i];
int yy=cow.y+dy[i];
if(check(xx,yy)){
vis[xx][yy]=1;
node t;
t.x=xx;
t.y=yy;
t.step=cow.step+1;
// if(check_door(xx,yy)){
// place next=next_door(xx,yy);
// t.x=next.x;
// t.y=next.y;
// vis[next.x][next.y]=1;
// }
q.push(t);
// if(map[xx][yy]=='='){
// point=t.step;
// return;
// }
}
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>map[i][j];
}
}
// cout<<endl;
// for(int i=1;i<=n;i++){
// for(int j=1;j<=m;j++){
// cout<<map[i][j];
// }
// cout<<endl;
// }
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(map[i][j]=='='){
ans_x=i;
ans_y=j;
}
if(map[i][j]=='@'){
start_x=i;
start_y=j;
}
}
}
bfs(start_x,start_y);
printf("%d",point);
return 0;
}
不明白为什么一直26pt,感觉该考虑到的都考虑到了
回复
共 3 条回复,欢迎继续交流。
正在加载回复...