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 ...
随机推荐
- logback写日志
https://blog.csdn.net/u010128608/article/details/76618263 https://blog.csdn.net/zhuyucheng123/articl ...
- java实现可安装的exe程序
java实现可安装的exe程序 通过编写Java代码,实现可安装的exe文件的一般思路: 1.在eclipse中创建java项目,然后编写Java代码,将编写好的Java项目导出一个.jar格式的ja ...
- 运用Python制作你心目中的完美女神脸!
简介 写这个项目的本来目的是通过构建一个神经网络来训练人脸图片,最后达到能根据图片自动判断美丑的效果.可能是因为数据集过小,或者自己参数一直没有调正确,无论我用人脸关键点训练还是卷积神经网络训练,最后 ...
- 用Python对微信好友进行简单统计分析,获取好友的基本信息!
早些日子有人问我我的微信里面有一共多少朋友,我就随后拉倒了通讯录最下面就找到了微信一共有多少位好友.然后他又问我,这里面你认识多少人?这一句话问的我很无语.一千多个好友我真的不知道认识的人有多少. ...
- LeetCode(138) Copy List with Random Pointer
题目 A linked list is given such that each node contains an additional random pointer which could poin ...
- CentOS 7.X 中systemctl命令用法详解
systemctl是RHEL 7 的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体.可以使用它永久性或只在当前会话中启用/禁用服务,下面来看CentOS 7.X 中 ...
- centos配置jdk
########## config jdk ########## export JAVA_HOME=/usr/local/java/jdk1.7.0_79 export CLASSPATH=.:${J ...
- vmware10下载地址
https://download3.vmware.com/software/wkst/file/VMware-Workstation-Full-10.0.1-1379776.x86_64.bundle ...
- Makefile基础(二)
上一章:C语言之Makefile基础(一) 上一章的Makefile写的中规中矩,比较繁琐,是为了讲清楚基本概念,其实Makefile有很多灵活的写法,可以写的更简洁,同时减少出错的可能 一个目标依赖 ...
- 大数据学习——SparkStreaming整合Kafka完成网站点击流实时统计
1.安装并配置zk 2.安装并配置Kafka 3.启动zk 4.启动Kafka 5.创建topic [root@mini3 kafka]# bin/kafka-console-producer. -- ...