三分 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> ...
随机推荐
- Operating system management of address-translation-related data structures and hardware lookasides
An approach is provided in a hypervised computer system where a page table request is at an operatin ...
- 289. Game of Live
According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellul ...
- Sum-(最大子序列和)
http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=652&pid=1003 题目大意: 给你一个序列,你随便找一 ...
- cogs——2419. [HZOI 2016]公路修建2
2419. [HZOI 2016]公路修建2 ★☆ 输入文件:hzoi_road2.in 输出文件:hzoi_road2.out 简单对比时间限制:1 s 内存限制:128 MB [题 ...
- HDU——1150 Machine Schedule
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- tomcat会自动解压webapps目录下的war包
如图,把war包放到tomcat的webapps目录,会被自动解压
- struts2学习笔记(二)—— 获取登录信息及计算在线人数
实现目的: 1.点击"Login"的超链接.进入登录页面 2.填写登录信息.提交表单,将用户信息保存进Session 3.显示用户名,并计算在线 ...
- Codeforces 479B. Towers 暴力
纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- swift编程语言基础教程 中文版
swift编程语言基础教程 中文版 http://download.csdn.net/detail/u014036026/7845491
- HTML5: 本地缓存
实现前端缓存,除了自己创建js保存(參考:http://blog.csdn.net/clementad/article/details/46807641).还能够利用html5的storage方法. ...