社区讨论
大红大紫 求调
P1825[USACO11OPEN] Corn Maze S参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lo1uef88
- 此快照首次捕获于
- 2023/10/23 03:09 2 年前
- 此快照最后确认于
- 2023/11/03 03:41 2 年前
救救我!!
“恭喜你喜提14/RE和2/WA!”
CPP#include<iostream>
#include<cmath>
using namespace std;
int n,m;
int tot[3001][3001];
char form[3001][3001];
int head=2,tail=1;
int flag[3001][3001];
int allow[2][900000];
int start_x,start_y,end_x,end_y;
int helpx[4]={0,0,-1,1};
int helpy[4]={1,-1,0,0};
int the_device_x;
int the_device_y;
void into(){
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>form[i][j];
if(form[i][j]=='#'){
start_x=i;
start_y=j;
}
if(form[i][j]=='='){
end_x=i;
end_y=j;
}
}
}
}
void find_device(char adress,int x,int y){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(form[i][j]==adress&&(x!=i||y!=j)){
the_device_x=i;
the_device_y=j;
return ;
}
}
}
}
bool if_device(int x,int y){
if(form[x][y]>='A'&&form[x][y]<='Z'){
return 1;
}
else{
return 0;
}
}
int search(){
allow[1][head]=start_x;
allow[2][head]=start_y;
while(head>=tail){
for(int i=0;i<4;i++){
if(form[allow[1][tail]+helpx[i]][allow[2][tail]+helpy[i]]!='#'){
head++;
if(if_device(allow[1][tail]+helpx[i],allow[2][tail]+helpy[i])){
find_device(form[allow[1][tail]+helpx[i]][allow[2][tail]+helpy[i]],allow[1][tail]+helpx[i],allow[2][tail]+helpy[i]);
allow[1][head]=the_device_x;
allow[2][head]=the_device_y;
tot[allow[1][tail]+helpx[i]][allow[2][tail]+helpy[i]]=tot[allow[1][tail]][allow[2][tail]]+1;
}
else if(form[allow[1][tail]+helpx[i]][allow[2][tail]+helpy[i]]=='='){
return tot[allow[1][tail]][allow[2][tail]]+1;
}
else{
allow[1][head]=allow[1][tail]+helpx[i];
allow[2][head]=allow[2][tail]+helpy[i];
tot[allow[1][tail]+helpx[i]][allow[2][tail]+helpy[i]]=tot[allow[1][tail]][allow[2][tail]]+1;
}
}
}
tail++;
}
}
void outto(){
cout<<search();
}
int main(){
into();
outto();
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...