知识点:二分,广度优先搜索
难度:4
这个题一开始没好好看题,然后在床上躺了一会儿,看了看题目,起来6分钟过了,首先看题目的问法就知道可以用二分做,是最小化最大值,我们要的答案在序列的右边,然后用二分把求最优解转化为判定问题,那么就是判断一个人在当前可承受的最大伤害值下,能不能从第一行走到最后一行,能就返回真,这个判定我用的是广搜,因为这个我掌握的比较好,深搜还要写递归函数,每次的判定用广搜就可以了,这个判定的要求仅仅是看能不能到达,比求最短路什么的要求还要弱,很好写,用广搜完全可以
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
struct state {
int x, y;
state() {}
state(int a, int b): x(a), y(b) {}
};
int n, m, a[N][N];
bool check(int x) {
int dist[N][N];
memset(dist, -1, sizeof(dist));
dist[0][0] = 0;
queue<state> q;
q.push(state(0, 0));
while (!q.empty()) {
state now = q.front(); q.pop();
if (now.x == n - 1) return true;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
for (int i = 0; i < 4; i++) {
int