当前位置:网站首页>Luogu p1902 assassinating Ambassador (two points | BFS)
Luogu p1902 assassinating Ambassador (two points | BFS)
2022-06-10 03:03:00 【Volume C】
Title Description

Ideas
Dichotomy adopt BFS Go through the answers
Code 1
#include <iostream>
#include <queue>
#include <utility>//pair
#include <cstring>
using namespace std;
typedef pair<int ,int> PII;
const int N = 1010;
int n, m, l = N, r = - N, mid, ans;
int p[N][N];
bool st[N][N];// It means have you ever been here prune !
int dx[4] = {
1, 0, -1, 0}, dy[4] = {
0, 1, 0, -1};
bool cheak(int x, int y, int maxn) {
//BFS
queue<PII> q;
q.push({
x, y});
st[x][y] = true;
while(!q.empty()) {
auto t = q.front();
q.pop();
for(int i = 0; i < 4; i ++) {
int x = t.first + dx[i], y = t.second + dy[i];
if(x < 1 || x > n || y < 1 || y > m || st[x][y] || p[x][y] > maxn) {
continue;
}
st[x][y] = true;
if(x == n) {
// If you can go to the n That's ok
return true;
} else {
q.push({
x, y});
}
}
}
return false;
}
int main () {
cin >> n >> m;
for(int i = 1; i <= n; i ++) {
for (int j = 1; j <= m; j ++) {
cin >> p[i][j];
r = max(r, p[i][j]);
l = min(l, p[i][j]);
}
}
while(l < r) {
// Find the left boundary
mid = (l + r) >> 1;
memset(st , false, sizeof st);
if(cheak(1, 1, mid)) {
r = mid;
ans = mid;
} else {
l = mid + 1;
}
}
cout << ans << endl;
return 0;
}
Thank you for reading
边栏推荐
- m3u8文件中的 m3u8标签与属性说明
- Tutorial on using midway
- P1082 [noip2012 improvement group] congruence equation
- Use of golang microservice instances protobuf and grpc
- Technology dry goods | linkis practice: analysis of new engine implementation process
- TS 23.122
- ^28js is single threaded
- Chapter VI semiconductor memory [microcomputer principle]
- Degraded judge (European expansion + enumeration)
- Arduino与Processing串口通信(match函数)
猜你喜欢
随机推荐
Knight Moves
ModuleNotFoundError: No module named ‘pip‘
leetcode:305. 岛屿的数量
P1516 青蛙的约会(扩欧)
TiDB经验分享02
Redis迭代查询详解及其使用:Scan命令、Sscan命令、Hscan命令、Zscan命令
Dataframe date data processing
Drawing of common charts
generate for 和 for 区别
flutter 双端扫码下载app
Degraded judge (European expansion + enumeration)
在子集合中第一個元素是由另一個數組插入的
uwsgi loading shared libraries:libicui18n. so. 58 exception handling
C # extension method (this in the method parameter)
midway的使用教程
P1516 frog's date (expanding Europe)
Electronic packaging error NPM err! code ELIFECYCLE npm ERR! errno 1
Jupyter notebook configuring virtual environments
Obtain the name of the province or city 【 project mall 】
^27 timer related problems


![College entrance examination [activities]](/img/da/b7e756a0a0298680142f62337f64b0.jpg)






