AtCoder-abc257_d Jumping Takahashi 2
Jumping Takahashi 2
dijkstra 或 Floyd 或 二分
dijkstra 枚举从每个点出发到所有点的最大代价的最小值
同理,Floyd 跑完之后再找这个最小值
二分答案,通过 bfs 判断是否有个点能跑遍历所有的点
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
#define pii pair<double, int>
const int maxn = 210;
const double eps = 1e-8;
ll gra[maxn][maxn];
int vis[maxn];
struct node
{
ll x, y, val;
node(){}
node(ll _x, ll _y, ll _v){x = _x; y = _y; val = _v;}
bool operator < (const node& a) const
{
return a.val < val;
}
}num[maxn];
ll dis(node& a, node& b)
{
return abs(a.x - b.x) + abs(a.y - b.y);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i=1; i<=n; i++)
cin >> num[i].x >> num[i].y >> num[i].val;
for(int i=1; i<=n; i++)
{
for(int j=i+1; j<=n; j++)
{
ll s = dis(num[i], num[j]);
gra[i][j] = (s + num[i].val - 1) / num[i].val;
gra[j][i] = (s + num[j].val - 1) / num[j].val;
}
}
ll ans = 1e17 + 10;
for(int i=1; i<=n; i++)
{
for(int j=j=1; j<=n; j++) vis[j] = 0;
priority_queue<node>q;
q.push(node(i, i, 0));
ll temp = 0;
int cnt = n;
while(q.size() && cnt)
{
node now = q.top();
q.pop();
if(vis[now.y]) continue;
cnt--;
vis[now.y] = 1;
temp = max(temp, now.val);
for(int j=1; j<=n; j++)
if(vis[j] == 0)
q.push(node(now.y, j, gra[now.y][j]));
}
ans = min(ans, temp);
}
cout << ans << endl;
return 0;
}