三分 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> ...
随机推荐
- 洛谷P2888 [USACO07NOV]牛栏Cow Hurdles
题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gan ...
- Thinkphp5.0 的请求方式
Thinkphp5.0 的请求方式 方法一(使用框架提供的助手函数): public function index(){ $request = request(); dump($request); } ...
- P1334 瑞瑞的木板 洛谷
https://www.luogu.org/problem/show?pid=1334 题目描述 瑞瑞想要亲自修复在他的一个小牧场周围的围栏.他测量栅栏并发现他需要N(1≤N≤20,000)根木板,每 ...
- Linux系统备份还原工具3(使用Clonezilla/再生龙对硬盘进行镜像和克隆,类似于Ghost)
说明:经过实验验证,再生龙主要是适合在本机还原原大小的分区,不适合将镜像备份还原到不同大小分区,期间可能有很多莫名奇妙的问题出现.硬盘对拷和PXE网刻这些没发现什么不好.如果要还原到别的电脑镜像制作时 ...
- Ionic3错误记录:navigation stack needs at least one root page
BUG场景:在 ActionSheetController 使用modalCtrl.create 创建模态框时报如下错误 原代码片段 解决方式: 重新设置root page
- 正则表达式lookahead and lookbehind zero-length assertions
正则表达式非常好的网站: https://www.regular-expressions.info/lookaround.html ---------------------------------- ...
- Cracking the Coding Interview 150题(一)
1.数组与字符串 1.1 实现一个算法,确定一个字符串的所有字符是否全都不同.假设不允许使用额外的数据结构,又该如何处理? 1.2 用C或C++实现void reverse(char* str)函数, ...
- Cocos2D实现上下滚动式状态窗体
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;) 有时候要显示的内容太多,我们无法在iOS设备的小屏幕上显示出来 ...
- 用JAVA生成老电影海报
先看图,再讲原理.生成效果对照: 机器全自己主动生成.是不是非常酷炫?:) 数字图像,由无数个像素组成,通常情况下,每一个像素包括有RGB三个值,算法原理事实上非常easy: 一,遍历全部像素,将RG ...
- Linq To Sql 增改删
using System; using System.Data.Linq.Mapping; namespace ConsoleApplication3 { [Table(Name = "te ...