Frogger POJ - 2253
题意
给你n个点,1为起点,2为终点,要求所有1到2所有路径中每条路径上最大值的最小值。
思路
不想打最短路
跑一边最小生成树,再扫一遍1到2的路径,取最大值即可
注意g++要用%f输出!!!
常数巨大的丑陋代码
# include <stdio.h>
# include <stdlib.h>
# include <iostream>
# include <string.h>
# include <math.h>
# include <algorithm>
using namespace std;
# define IL inline
# define RG register
# define UN unsigned
# define ll long long
# define rep(i, a, b) for(RG int i = a; i <= b; i++)
# define per(i, a, b) for(RG int i = b; i >= a; i--)
# define uev(e, u) for(RG int e = ft[u]; e != -1; e = edge[e].nt)
# define mem(a, b) memset(a, b, sizeof(a))
# define max(a, b) (((a) > (b)) ? (a) : (b))
# define min(a, b) (((a) < (b)) ? (a) : (b))
# define Swap(a, b) a ^= b, b ^= a, a ^= b;
# define Sqr(a) ((a) * (a))
IL ll Get(){
RG char c = '!'; RG ll x = 0, z = 1;
while(c != '-' && (c < '0' || c > '9')) c = getchar();
if(c == '-') z = -1, c = getchar();
while(c >= '0' && c <= '9') x = x*10+c-'0', c = getchar();
return x*z;
}
const int MAXN = 1000001;
int ft[MAXN], n, cnt, vis[MAXN], fa[MAXN], m;
struct Edge{
int to, nt;
double f;
} edge[MAXN<<1];
struct _Edge{
int u, v;
double f;
IL bool operator < (_Edge b) const{
return f < b.f;
}
} _edge[MAXN];
double ans, x[MAXN], y[MAXN];
IL void Add(RG int u, RG int v, RG double f){
edge[cnt] = (Edge){v, ft[u], f}; ft[u] = cnt++;
}
IL int Find(RG int x){
return fa[x] == x ? x : Find(fa[x]);
}
IL void Kruskal(){
sort(_edge + 1, _edge + m + 1);
RG int t = 0;
rep(i, 1, m){
if(t == n - 1) break;
RG int u = Find(_edge[i].u), v = Find(_edge[i].v);
if(u != v){
t++; fa[u] = v;
Add(u, v, _edge[i].f); Add(v, u, _edge[i].f);
}
}
}
IL void Dfs(RG int u, RG double ans1){
if(u == 2) ans = ans1;
uev(e, u){
RG int v = edge[e].to;
if(vis[v]) continue;
vis[v] = 1;
RG double f = max(ans1, edge[e].f);
Dfs(v, f);
}
}
int main(){
RG int T = 0;
n = Get();
while(n){
T++;
mem(ft, -1); m = ans = cnt = 0;
rep(i, 1, n) scanf("%lf%lf", &x[i], &y[i]);
rep(i, 1, n-1) rep(j, i+1, n){
double dis = sqrt(Sqr(x[i] - x[j]) + Sqr(y[i] - y[j]));
_edge[++m] = (_Edge){i, j, dis};
}
rep(i, 1, n) fa[i] = i;
Kruskal();
mem(vis, 0); vis[1] = 1;
Dfs(1, 0);
printf("Scenario #%d\nFrog Distance = %.3f\n\n", T, ans);
n = Get();
}
return 0;
}
Frogger POJ - 2253的更多相关文章
- floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253
The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...
- Frogger POJ - 2253(求两个石头之间”所有通路中最长边中“的最小边)
题意 题目主要说的是,有两只青蛙,在两个石头上,他们之间也有一些石头,一只青蛙要想到达另一只青蛙所在地方,必须跳在石头上.题目中给出了两只青蛙的初始位置,以及剩余石头的位置,问一只青蛙到达另一只青 ...
- Frogger - poj 2253 (Dijkstra)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28802 Accepted: 9353 Description Fr ...
- kuangbin专题专题四 Frogger POJ - 2253
题目链接:https://vjudge.net/problem/POJ-2253 思路: 从一号到二号石头的所有路线中,每条路线中都个子选出该路线中两点通路的最长距离,并在这些选出的最长距离选出最短路 ...
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- POJ 2253 Frogger(dijkstra 最短路
POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
随机推荐
- 【Tools】ubuntu16.04安装搜狗输入法
Ubuntu16,04 安装搜狗输入法 1.下载搜狗输入法的安装包 下载地址为:http://pinyin.sogou.com/linux/ 2.按键Ctr+Alt+T打开终端,输入以下命令切换到下载 ...
- 以kaggle-titanic数据为基础的完整的机器学习
1. 引入所有需要的包 # -*- coding:utf-8 -*- # 忽略警告 import warnings warnings.filterwarnings('ignore') # 引入数据处理 ...
- Asp.Net Core2.0 基于QuartzNet任务管理系统
Quartz.NET官网地址:https://www.quartz-scheduler.net/ Quartz.NET文档地址:https://www.quartz-scheduler.net/doc ...
- Yii2-admin的详细使用教程
Yii2-admin的详细使用教程 参考:http://www.yiichina.com/tutorial/571 http://www.kancloud.cn/curder/yii/24775 ...
- Flask從入門到入土(一)——程序的基本結構
一.初始化 所有Flask程序都必須創建一個程序實例.Web服務器使用一種名爲Web服務器網關接口的協議,把接收自客戶端的所有請求都轉交給這個對象處理.程序實例書Flask類的對象,創建代碼: fro ...
- 静态编译程序 依赖于 Qt 和 Opencv 静态库 会出现 jpeg jpg 图像格式保存崩溃的情况,这是什么原因?
双方依赖的 jpeg 静态库源码版本冲突,重新静态编译库,都采用一致版本即可.
- C#标识符
- HDU - 1241 dfs or bfs [kuangbin带你飞]专题一
8个方向求联通块,经典问题. AC代码 #include<cstdio> #include<cstring> #include<algorithm> #includ ...
- 【BZOJ2127】happiness
Time Limit: 1000 ms Memory Limit: 256 MB Description 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为 ...
- 多key业务,数据库水平切分架构一次搞定
数据库水平切分是一个很有意思的话题,不同业务类型,数据库水平切分的方法不同. 本篇将以"订单中心"为例,介绍"多key"类业务,随着数据量的逐步增大,数据库性能 ...