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 ...
随机推荐
- bp神经网络原理
bp(back propagation)修改每层神经网络向下一层传播的权值,来减少输出层的实际值和理论值的误差 其实就是训练权值嘛 训练方法为梯度下降法 其实就是高等数学中的梯度,将所有的权值看成自变 ...
- 【mysql】The server quit without updating PID file
groupadd mysql useradd -r -g mysql mysql cd /usr/local/mysql chown -R mysql:mysql . scripts/mysql_ ...
- Python学习day01
age = 23 count=0 while count<3: guess_age = int (input("My age:")) if age ==guess_age: ...
- 分享一个编程学习网站:https://github.com/justjavac/free-programming-books-zh_CN
分享一个编程学习网站:https://github.com/justjavac/free-programming-books-zh_CN
- NXP低功耗蓝牙集成芯片QN9080C的时钟配置
/*************************************************************************************************** ...
- POJ:1094-Sorting It All Out(拓扑排序经典题型)
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Description An ascending sorted sequence ...
- HDU 5402 模拟 构造 Travelling Salesman Problem
题意: 有一个n * m的数字矩阵,每个格子放着一个非负整数,从左上角走到右下角,每个格子最多走一次,问所经过的格子的最大权值之和是多少,并且输出一个路径. 分析: 如果n和m有一个是偶数的话,那么只 ...
- Leetcode 476.数字的补数
数字的补数 给定一个正整数,输出它的补数.补数是对该数的二进制表示取反. 注意: 给定的整数保证在32位带符号整数的范围内. 你可以假定二进制数不包含前导零位. 示例 1: 输入: 5 输出: 2 解 ...
- JAVA-两种后台页面跳转方式
1.请求转发 RequestDispatcher rd = request.getRequestDispatcher("url"); rd.forward(request, res ...
- [git 学习篇] git checkout 撤销修改
git status 查看当前创库情况 liuzhipeng@exdroid43:~/pad/pad-test$ git status 位于分支 master 您的分支与上游分支 'origin/ma ...