三分 POJ 2420 A Star not a Tree?
/*
题意:求费马点
三分:对x轴和y轴求极值,使到每个点的距离和最小
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath> const int MAXN = 1e2 + ;
const int INF = 0x3f3f3f3f;
double x[MAXN], y[MAXN];
int n; double sum(double x1, double y1) {
double res = ;
for (int i=; i<=n; ++i) {
res += sqrt ((x1 - x[i]) * (x1 - x[i]) + (y1 - y[i]) * (y1 - y[i]));
}
return res;
} double cal(double x1) {
int l = 0.0, r = 10000.0;
for (int i=; i<=; ++i) {
double lmid = (l + r) / ;
double rmid = (lmid + r) / ;
if (sum (x1, lmid) < sum (x1, rmid)) r = rmid;
else l = lmid;
}
return sum (x1, l);
} int main(void) { //POJ 2420 A Star not a Tree?
//freopen ("POJ_2420.in", "r", stdin); while (scanf ("%d", &n) == ) {
for (int i=; i<=n; ++i) {
scanf ("%lf%lf", &x[i], &y[i]);
} double l = 0.0, r = 10000.0;
for (int i=; i<=; ++i) {
double lmid = (l + r) / ;
double rmid = (lmid + r) / ;
if (cal (lmid) < cal (rmid)) r = rmid;
else l = lmid;
}
printf ("%.0f\n", cal (l));
} return ;
}
三分 POJ 2420 A Star not a Tree?的更多相关文章
- [POJ 2420] A Star not a Tree?
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4058 Accepted: 200 ...
- POJ 2420 A Star not a Tree? 爬山算法
B - A Star not a Tree? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...
- POJ 2420 A Star not a Tree? (计算几何-费马点)
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3435 Accepted: 172 ...
- poj 2420 A Star not a Tree?——模拟退火
题目:http://poj.org/problem?id=2420 精度设成1e-17,做三遍.ans设成double,最后再取整. #include<iostream> #include ...
- poj 2420 A Star not a Tree? —— 模拟退火
题目:http://poj.org/problem?id=2420 给出 n 个点的坐标,求费马点: 上模拟退火. 代码如下: #include<iostream> #include< ...
- POJ 2420 A Star not a Tree?(模拟退火)
题目链接 居然1Y了,以前写的模拟退火很靠谱啊. #include <cstdio> #include <cstring> #include <string> #i ...
- POJ 2420 A Star not a Tree?【爬山法】
题目大意:在二维平面上找出一个点,使它到所有给定点的距离和最小,距离定义为欧氏距离,求这个最小的距离和是多少(结果需要四舍五入)? 思路:如果不能加点,问所有点距离和的最小值那就是经典的MST,如果只 ...
- 【POJ】2420 A Star not a Tree?(模拟退火)
题目 传送门:QWQ 分析 军训完状态不好QwQ,做不动难题,于是就学了下模拟退火. 之前一直以为是个非常nb的东西,主要原因可能是差不多省选前我试着学一下但是根本看不懂? 骗分利器,但据说由于调参困 ...
- 【POJ】2420 A Star not a Tree?
http://poj.org/problem?id=2420 题意:给n个点,求一个点使得到这个n个点的距离和最短,输出这个最短距离(n<=100) #include <cstdio> ...
随机推荐
- TKmybatis的框架介绍和原理分析及Mybatis新特性
tkmybatis是在mybatis框架的基础上提供了很多工具,让开发更加高效,下面来看看这个框架的基本使用,后面会对相关源码进行分析,感兴趣的同学可以看一下,挺不错的一个工具 实现对员工表的增删改查 ...
- [NOIP2008] 提高组 洛谷P1149 火柴棒等式
题目描述 给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A.B.C是用火柴棍拼出的整数(若该数非零,则最高位不能是0).用火柴棍拼数字0-9的拼法如图所示: 注意: 加号与等号各自 ...
- PatentTips - Hierarchical RAID system including multiple RAIDs
BACKGROUND OF THE INVENTION The present invention relates to a storage system offering large capacit ...
- Codeforces 629D Babaei and Birthday Cake(树状数组优化dp)
题意: 线段树做法 分析: 因为每次都是在当前位置的前缀区间查询最大值,所以可以直接用树状数组优化.比线段树快了12ms~ 代码: #include<cstdio> #include< ...
- Mayor's posters-POJ2528(线段树+离散化)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- HashMap的工作原理以及代码实现,为什么要转换成红黑树?
原理参考:https://blog.csdn.net/striveb/article/details/84657326 总结: 为什么当桶中键值对数量大于8才转换成红黑树,数量小于6才转换成链表? 参 ...
- 【SQL Server 学习系列】-- 收缩数据库文件大小
USE WebExam; GO ALTER DATABASE WebExam SET RECOVERY SIMPLE; GO -- 收缩文件到 1 MB. ); GO ALTER DATABASE W ...
- js类继承扩展super
相应的资料https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/super 例子: class Pol ...
- keepalived + lvs marster 与 backup 之间的 高可用
简介 keepalived 是linux下一个轻量级的高可用解决方案,它与HACMP实现功能类似,都可以实现服务或者网络的高可用,但是又有差别:hacmp是一个专业的.功能完善的高可用软件,它提供了H ...
- Jenkins 使用
Jenkins 安装 Jenkins是用Java语言开发的系统,首先要确定服务器上已经安装JDK或者JRE. 安装方式一 直接运行java –jar Jenkins.war,在浏览器中输入 http: ...