社区讨论
90pts bfs做法 #2TLE
P1434[SHOI2002] 滑雪参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mhjnt5ws
- 此快照首次捕获于
- 2025/11/04 05:35 4 个月前
- 此快照最后确认于
- 2025/11/04 05:35 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int n,m,ans=1;
int maps[105][105];
bool vis[105][105];
int go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct xy{
int x,y;
};
struct node{
int x,y,dist;
vector<xy>was;
};
void bfs(int firsx,int firsy){
queue<node>q;
node t1,t2;
t1.dist=1;
t1.x=firsx;
t1.y=firsy;
vector<xy>p;
xy w;w.x=t1.x;
w.y=t1.y;
p.push_back(w);
t1.was=p;
vis[firsx][firsy]=1;
q.push(t1);
while (!q.size()==0){
t1=q.front();
// printf("[debug]x=%d y=%d dist=%d ans=%d\n",t1.x,t1.y,t1.dist,ans);
// for (int i=0;i<t1.was.size();++i)cout<<t1.was[i].x<<' '<<t1.was[i].y<<" | ";
// cout<<endl<<endl;
for (int i=0;i<4;++i){
int nx=t1.x+go[i][0];
int ny=t1.y+go[i][1];
int ndist=t1.dist+1;
xy t;t.x=nx;t.y=ny;
if (nx>=1&&nx<=n&&ny>=1&&ny<=m&&vis[nx][ny]==0&&maps[nx][ny]<maps[t1.x][t1.y]){
t2.was=t1.was;
t2.was.push_back(t);
t2.x=nx;
t2.y=ny;
t2.dist=ndist;
q.push(t2);
ans=max(ans,t2.dist);
}
}
vis[t1.x][t1.y]=0;
q.pop();
}
return ;
}
int main(){
cin>>n>>m;
for (int i=1;i<=n;++i){
for (int j=1;j<=m;++j){
cin>>maps[i][j];
}
}
for (int i=1;i<=n;++i){
for (int j=1;j<=m;++j){
bfs(i,j);
}
}
cout<<ans;
return 0;
}
/*
5 5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
*/
不知道为什么一卡常就0pts,不过卡完常就0TLE了
回复
共 1 条回复,欢迎继续交流。
正在加载回复...