Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 34968   Accepted: 11235

Description

Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead reach her by jumping.
Unfortunately Fiona's stone is out of his jump range. Therefore
Freddy considers to use other stones as intermediate stops and reach her
by a sequence of several small jumps.

To execute a given sequence of jumps, a frog's jump range obviously
must be at least as long as the longest jump occuring in the sequence.

The frog distance (humans also call it minimax distance) between two
stones therefore is defined as the minimum necessary jump range over
all possible paths between the two stones.

You are given the coordinates of Freddy's stone, Fiona's stone and
all other stones in the lake. Your job is to compute the frog distance
between Freddy's and Fiona's stone.

Input

The
input will contain one or more test cases. The first line of each test
case will contain the number of stones n (2<=n<=200). The next n
lines each contain two integers xi,yi (0 <= xi,yi <= 1000)
representing the coordinates of stone #i. Stone #1 is Freddy's stone,
stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a
blank line following each test case. Input is terminated by a value of
zero (0) for n.

Output

For
each test case, print a line saying "Scenario #x" and a line saying
"Frog Distance = y" where x is replaced by the test case number (they
are numbered from 1) and y is replaced by the appropriate real number,
printed to three decimals. Put a blank line after each test case, even
after the last one.

Sample Input

2
0 0
3 4 3
17 4
19 4
18 5 0

Sample Output

Scenario #1
Frog Distance = 5.000 Scenario #2
Frog Distance = 1.414

题意:一只青蛙要从1走到2,求所有1-2的路径中最长的子段中最短的那条(minimax)。。有点难懂啊,,打个比方。
1 2 2
1 3 1.5
2 3 1
那么我们有 1 2 可以选择 ,路径长度为 2
还有 1 3 2 可以选择 路径长度 为 1.5+1 = 2.5
所以我们选择 1 3 2 答案为 1.5
这里可以用贪心的思想,利用kruskal进行添边,如果1 2 联通了就必定是这一条。。开始想复杂了,用二分+网络流去解。。结果果断TLE
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<iostream>
using namespace std;
const int N = ;
struct Point{
double x,y;
}p[N];
struct Edge{
int s,t;
double v;
}edge[N*N];
int father[N];
int n;
void init(){
for(int i=;i<=n;i++) father[i] = i;
}
double dis(Point a,Point b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int _find(int x){
if(x==father[x]){
return father[x];
}
return father[x] = _find(father[x]);
}
int cmp(Edge a,Edge b){
return a.v<b.v;
}
double kruskal(int m){
double MAX = -;
sort(edge+,edge++m,cmp);
for(int i=;i<=m;i++){
int a = _find(edge[i].s);
int b = _find(edge[i].t);
if(a!=b) {
father[a] = b;
}
if(_find()==_find()){
MAX = edge[i].v;
return MAX;
}
}
}
int main()
{
int t = ;
while(scanf("%d",&n)!=EOF&&n)
{
init();
for(int i=; i<=n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
int m=;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
double d = dis(p[i],p[j]);
edge[m].s = i;
edge[m].t = j;
edge[m++].v = d;
}
}
m--;
double res = kruskal(m);
printf("Scenario #%d\nFrog Distance = %.3lf\n\n",t++,sqrt(res));
}
return ;
}

poj 2253(kruskal)的更多相关文章

  1. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  2. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

  3. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  4. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  5. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  6. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  7. poj 2253 Frogger【最小生成树变形】【kruskal】

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30427   Accepted: 9806 Descript ...

  8. Poj(2253),Dijkstra松弛条件的变形

    题目链接:http://poj.org/problem?id=2253 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通 ...

  9. POJ 2253 Frogger 最短路 难度:0

    http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...

随机推荐

  1. Flask-蓝图、模型与CodeFirst

    一.应用.蓝图与视图函数 结构,如图: Flask最上层是app核心对象 ,在这个核心对象上可以插入很多蓝图,这个蓝图是不能单独存在的,必须将app作为插板插入app ,在每一个蓝图上,可以注册很多静 ...

  2. 二分查找、upper_bound、lower_bound

    整理及总结二分查找的判断和边界细节 修改版 package com.leej.binarysearch; import java.util.Arrays; /** * @author jerry * ...

  3. nodejs开发过程中遇到的一些插件记录

    1.chalk Github:https://github.com/chalk/chalk   终端样式定制插件,可自定义输出日志的样式. 1.semver   管网:https://semver.o ...

  4. vue 项目白屏解决方案

    在做的项目是使用 vue-cli 脚手架为基础的,只能使用微信浏览器打开的.在某次更新功能代码后,被反馈在一些手机上会出现白屏.经过一番探索,多管齐下解决了问题 白屏可能的原因: es6 代码没有被编 ...

  5. destoon去除编辑器替换图片删除原图功能,删除信息删除相关图片功能

    去除这些功能会造成大量垃圾图片,但是客户存在大量复制内容,其中图片一样,为了防止客户替换其中一个图片或者删除信息 造成其他复制信息图片丢失 去除文章模型级联图片功能. 对应模块class.php se ...

  6. Linux 安装Nginx+PHP+MySQL教程

    一.安装nginx 通过yum安装openssl: yum -y install openssl openssl-devel 通过yum安装pcre: yum -y install pcre-deve ...

  7. Word 借助VBA一键实现插入交叉引用

    最近写论文的时候,经常需要向上或向下插入题注的交叉引用,word 自带的界面往往需要操作多次,才能实现插入.而平时使用较多的只是交叉引用附近的题注,比如如图1.1所示,在图1.1中等,距离较远的引用则 ...

  8. python中文件操作的六种模式及对文件某一行进行修改的方法

    一.python中文件操作的六种模式分为:r,w,a,r+,w+,a+ r叫做只读模式,只可以读取,不可以写入 w叫做写入模式,只可以写入,不可以读取 a叫做追加写入模式,只可以在末尾追加内容,不可以 ...

  9. LeetCode(147) Insertion Sort List

    题目 Sort a linked list using insertion sort. 分析 实现链表的插入排序 注意: 程序入口的特殊输入判断处理! 节点的链接处理,避免出现断链! AC代码 /** ...

  10. Tracer Deployment UVALive - 8271 二分图匹配

    复习二分图又想起了这道题,裸的二分图匹配,直接匈牙利算法就可以了,mark一下这个比较好用的稠密图匈牙利算法模板 题目:题目链接 AC代码: #include <iostream> #in ...