poj 2253(kruskal)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 34968 | Accepted: 11235 |
Description
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
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
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)的更多相关文章
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- poj 2253 Frogger (最长路中的最短路)
链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
- 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 ...
- poj 2253 Frogger【最小生成树变形】【kruskal】
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30427 Accepted: 9806 Descript ...
- Poj(2253),Dijkstra松弛条件的变形
题目链接:http://poj.org/problem?id=2253 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通 ...
- POJ 2253 Frogger 最短路 难度:0
http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...
随机推荐
- 消息队列之 Kafka
转 https://www.jianshu.com/p/2c4caed49343 消息队列之 Kafka 预流 2018.01.15 16:27* 字数 3533 阅读 1114评论 0喜欢 12 K ...
- mysql 在线添加字段
使用工具pt-online-schema-change #! /bin/bash stime=`date +%s` echo "增加字段开始测试时间为:`date +%H:%M:%S`&qu ...
- 设置mysql允许外部连接访问
错误信息: SQL Error (1130): Host ‘192.168.1.88’ is not allowed to connect to this MySQL server 说明所连接的用户帐 ...
- UVA1589——xiangqi
开始碰到这个题时觉得太麻烦了直接跳过没做,现在放假了再次看这个题发现没有想象中那么麻烦,主要是题目理解要透彻,基本思路就是用结构体数组存下红方棋子,让黑将军每次移动一下,看移动后是否有一个红方棋子可以 ...
- android adb虚拟机对应的键盘命令
HOME Home button 主界面键 F2, PAGEUP Menu (Soft-Left) ...
- MySQL数据库详解(一)执行SQL查询语句时,其底层到底经历了什么?
一条SQL查询语句是如何执行的? 前言 大家好,我是WZY,今天我们学习下MySQL的基础框架,看一件事千万不要直接陷入细节里,你应该先鸟瞰其全貌,这样能够帮助你从高维度理解问题.同样,对于MyS ...
- canvas 动画库 CreateJs 之 EaselJS(上篇)
本文来自网易云社区 作者:田亚楠 须知 本文主要是根据 createjs 中的 EaselJS 在 github 上的 tutorials 目录下的文章整理而来 (原文链接),同时也包含了很多本人的理 ...
- 03_HibernateSessionFactory源码分析
文章导读: 讲解了一个线程为什么要使用同一个connection, 我们分析了HiberatenSessionFactory的实现机制, 然后根据Hibernate的写法重构了我们的代码. 最后测试可 ...
- day05_03 字符串格式化
pycharm小技巧,一般情况下都需要在代码前注释以下作者以及创建日期 但是如何让软件默认生成呢? 格式化输出 可以用占位符 %s string的缩写 #__author:Administra ...
- 创建sql作业(JOB)
在SQL Server日常需求处理中,会遇到定时执行或统计数据的需求,这时我们可以通过作业(JOB)来处理,从而通过代理的方式来实现数据的自动处理.一下为SQL Server中创建作业的脚本,供大家参 ...