POJ 2253 Difference of Clustering
题意:给出一堆点,求从起点到终点的所有通路中相邻点的距离的最大值的最小值。(意思就是自己百度吧……)
解法:用相邻点的最大值作为权值代替路径的距离跑最短路或者最小生成树。然后我写了一个我以为是优化过的dijkstra但好像是prim的东西- -啊差不多啦……
总之用优先队列维护权值进行广搜……然后交G++一直wa也不知道为啥……交了C++就过了……
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
struct node
{
int x, y;
}p[205];
struct node1
{
int point;
int step;
node1(int point, int step) : point(point), step(step) {}
node1() {}
bool operator < (const node1 &tmp) const
{
return step > tmp.step;
}
};
int n;
int caldis(node a, node b)
{
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
int dis[205][205];
vector <int> edge[205];
bool vis[205];
double bfs()
{
memset(vis, 0, sizeof vis);
priority_queue <node1> q;
q.push(node1(0, 0.0));
while(!q.empty())
{
node1 tmp = q.top();
q.pop();
vis[tmp.point] = 1;
if(tmp.point == 1) return tmp.step;
for(int i = 0; i < edge[tmp.point].size(); i++)
{
if(!vis[edge[tmp.point][i]]) q.push(node1(edge[tmp.point][i], max(tmp.step, dis[tmp.point][edge[tmp.point][i]])));
}
}
}
int main()
{
int cse = 1;
while(~scanf("%d", &n) && n)
{
for(int i = 0; i < n; i++)
scanf("%d%d", &p[i].x, &p[i].y);
int maxn = 0.0;
for(int i = 0; i < n; i++)
edge[i].clear();
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
{
if(i == j) continue;
int tmp = caldis(p[i], p[j]);
edge[i].push_back(j);
dis[i][j] = tmp;
}
double ans = bfs();
printf("Scenario #%d\nFrog Distance = %.3lf\n\n", cse++, sqrt(ans));
}
return 0;
}
POJ 2253 Difference of Clustering的更多相关文章
- 最短路(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 ...
- HDU 5489 Difference of Clustering 图论
Difference of Clustering Problem Description Given two clustering algorithms, the old and the new, y ...
- HDU 5486 Difference of Clustering 暴力模拟
Difference of Clustering HDU - 5486 题意:有n个实体,新旧两种聚类算法,每种算法有很多聚类,在同一算法里,一个实体只属于一个聚类,然后有以下三种模式. 第一种分散, ...
- 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),Dijkstra松弛条件的变形
题目链接:http://poj.org/problem?id=2253 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通 ...
随机推荐
- [转载]实战Linux下VMware虚拟机根目录空间扩充
[转载]实战Linux下VMware虚拟机根目录空间扩充 (2011-07-31 21:34:34) 转载▼ 标签: 转载 原文地址:实战Linux下VMware虚拟机根目录空间扩充作者:shar ...
- 将DJANGO管理界面的filter_horizontal移到前面来复用
参考URL: http://www.hoboes.com/Mimsy/hacks/replicating-djangos-admin/reusing-djangos-filter_horizontal ...
- hadoop 2.2.0的datanode中存储block的多个文件夹的负载均衡问题
hadoop的分布式文件系统HDFS的存储方式是,将数据分成block,分布式存储在整个hadoop集群的datanode中,每个block默认的大小是64M,这些block文件的具体存储位置是在ha ...
- lintcode:递归打印数字
题目 用递归打印数字 用递归的方法找到从1到最大的N位整数. 样例 给出 N = 1, 返回[1,2,3,4,5,6,7,8,9]. 给出 N = 2, 返回[1,2,3,4,5,6,7,8,9,10 ...
- Shell最多支持多少个参数
本文转自:http://www.jb51.net/article/56548.htm 这篇文章主要介绍了Shell最多支持多少个参数?本文是对Shell最多可以输入多少个参数的一篇测试文章,需要的 ...
- Hibernate配置文件hbm主键的generator可选项
Hibernate配置文件hbm主键的generator可选项 1.自动增长identity 适用于MySQL.DB2.MS SQL Server,采用数据库生成的主键,用于为long.short.i ...
- MySQL登录报错"Access denied for user 'root'@'localhost' (using password: YES)"
最近登录MySQL时候总报错: # mysql -uroot -p Enter password: ERROR (): Access denied for user 'root'@'localhost ...
- (转)Struts 拦截器
一.拦截器是怎么实现: 实际上它是用Java中的动态代理来实现的 二.拦截器在Struts2中的应用 对于Struts2框架而言,正是大量的内置拦截器完成了大部分操作.像params拦截器将http请 ...
- 剖析MapReduce 作业运行机制
包含四个独立的实体: · Client Node 客户端:编写 MapReduce代码,配置作业,提交MapReduce作业. · JobTracker :初始化作业,分配作业,与 TaskTra ...
- javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint
使用hibernate validator出现上面的错误, 需要 注意 @NotNull 和 @NotEmpty 和@NotBlank 区别 @NotEmpty 用在集合类上面@NotBlank 用 ...