poj 2420
太虚假了。
我为什么要手贱点开submission?
这道题两天之前被一个学弟A了。
?
我退役了。
其实就是爬山吧。。好像有的题解还分方向什么的完全没必要吧。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <stdlib.h>
#define pii pair<int,int>
using namespace std;
typedef double db;
const db INF = 1e100;
const db delta = 0.98;
const db eps = 1e-;
int sign(db k){
if (k>eps) return ; else if (k<-eps) return -; return ;
}
int cmp(db k1,db k2){return sign(k1-k2);}
struct point {
db x,y;
point operator - (const point &k1)const { return point{x-k1.x,y-k1.y};};
db abs(){ return sqrt(x*x+y*y);}
db dis(point k1){ return ((*this)-k1).abs();}
};
db random(){
return (rand()&?:-)*rand()*1.0/;
}
int n;point p[];
point ans[];
db F(point x){
db res = ;
for(int i=;i<n;i++){
res+=x.dis(p[i]);
}
return res;
}
void SA(){
db t = ;
while (t>eps){
for(int i=;i<;i++){
db tmp = F(ans[i]);
for(int j=;j<;j++){
point _x=point{ans[i].x+random()*t,ans[i].y+random()*t};
db f = F(_x);
if(tmp>f) {
tmp = f;
ans[i]=_x;
}
}
}
t*=delta;
}
db ed = INF;
for(int i=;i<;i++)
ed=min(ed,F(ans[i]));
printf("%.0f",ed);
}
int main(){
ios::sync_with_stdio(false);
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
SA();
}
poj 2420的更多相关文章
- 三分 POJ 2420 A Star not a Tree?
题目传送门 /* 题意:求费马点 三分:对x轴和y轴求极值,使到每个点的距离和最小 */ #include <cstdio> #include <algorithm> #inc ...
- poj 2420,模拟退火算法,费马点
题目链接:http://poj.org/problem?id=2420 题意:给n个点,找出一个点,使这个点到其他所有点的距离之和最小,也就是求费马点. 参考链接:http://www.cnblogs ...
- 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?
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4058 Accepted: 200 ...
- POJ 2420 A Star not a Tree?(模拟退火)
题目链接 居然1Y了,以前写的模拟退火很靠谱啊. #include <cstdio> #include <cstring> #include <string> #i ...
- POJ 2420:A Star not a Tree?
原文链接:https://www.dreamwings.cn/poj2420/2838.html A Star not a Tree? Time Limit: 1000MS Memory Limi ...
- 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 ...
随机推荐
- SQL批量更新数据
SQL批量更新数据 step1:导入Excel数据, 具体见百度.注意点:一列中含有float型数据和文本数据的时候,导入要将Excel中的表格属性改成文本,或在数字项目前加个单引号. step2 ...
- Intel处理器技术文档
1.intel程序员手册(1986).pdf 下载地址 2.Intel® 64 and IA-32 Architectures Software Developer Manuals 下载链接 3. ...
- 无法打开运行空间池,服务器管理器winrm插件可能已损坏或丢失
在使用windows2012 的服务器或云主机时,服务器安装不了iis服务. 提示 “无法打开运行空间池,服务器管理器winrm插件可能已损坏或丢失”. 这个问题可能的原因是您的机器未设置虚拟内存,可 ...
- android平台修改默认语言的那点事
转自:https://blog.csdn.net/qinghua0706/article/details/8243858 最近开始做智能机,用的是展讯6820平台,第一个需求就是改默认语言,一般碰到不 ...
- 解决Linux系统80端口被占用的问题
有Linux在centos下面安装webmail服务遇到80端口被占用的问题,导致无法继续安装,下面详细介绍下Linux如何查看.查找.关闭监听80端口服务以更好的的解决80端口被占用的问题. 一.查 ...
- ionic android升级检查
https://www.cnblogs.com/zxj159/p/4421578.html 坑: 放到cordova.file.DataDirectory下载异常? 只好cordova.file.ex ...
- SpringBoot2.0针对请求参数@RequestBody验证统一拦截
title: "SpringBoot2.0针对请求参数@RequestBody验证的统一拦截"categories: SpringBoot2.0 Shirotags: Spring ...
- NOIP2010普及组 三国游戏
题目OJ地址 http://codevs.cn/problem/1129/ https://www.luogu.org/problemnew/show/P1199 题目描述 Description 小 ...
- Mongodb系列- spring-data-mongodb使用MongoTemplate实现分页查询
在用spring-data-mongodb框架开发的过程中,需要实现分页查询,就百度了下,没找到满意的又google了下,找到了思路. 在spring-data-mongodb 官方文档中,建议你使用 ...
- Introducing Apache Spark Datasets(中英双语)
文章标题 Introducing Apache Spark Datasets 作者介绍 Michael Armbrust, Wenchen Fan, Reynold Xin and Matei Zah ...