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 ...
随机推荐
- 2、html补充
今天补充几个html标签 <body>内常用标签 1.<div>和<span> <div></div> : <div>只是一个块 ...
- aix 查看内存,CPU 配置信息
内存lsattr -El mem0cpu lsdev -C |grep procCPU的信息lsattr -El proc0 #bootinfo -r查看物理内存 使用命令# lsdev ...
- 修改编辑器为Markdown编辑器
一直都在使用cnblogs的TinyMCE,不过感觉好久不更新,还是用Markdown吧,写多了Markdown 还真是受感染呢. 学习下吧,边学便用. 参考链接: 序列图 [简明版]有道云笔记Mar ...
- Glide终于解决了同时绑定多个webp格式图片的问题
前端时间,要给项目换个图片加载的库,使用Glide 3.7版本进行测试, 发现在快速滑动列表(每个item都会加载一个app的图标,采用webp格式,即同时加载多个webp格式)的时候,一屏至少有2- ...
- Js实现Table动态添加一行的小例子
<form id="form1" runat="server"> <div> <table id=" style=&qu ...
- 您的第一个C++Builder程序(Hello, world!)
最近有些老旧的项目是C++Builder开发的,虽然和Delphi的IDE的界面和操作十分相似,但是还是找本<C++ Builder 5 Developer's Guide>来看看熟悉下, ...
- SSE图像算法优化系列七:基于SSE实现的极速的矩形核腐蚀和膨胀(最大值和最小值)算法。
因未测试其他作者的算法时间和效率,本文不敢自称是最快的,但是速度也可以肯定说是相当快的,在一台I5机器上占用单核的资源处理 3000 * 2000的灰度数据用时约 20ms,并且算法和核心的大小是无关 ...
- WPF双向数据绑定总结
参考官方:https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/data/data-binding-wpf 实例程序:https://files. ...
- react-native init的时候出现问题:npm WARN React-native@0.35.0 requires a peer of react@~15.3.1 but none was
react-native init的时候出现问题:npm WARN React-native@0.35.0 requires a peer of react@~15.3.1 but none was ...
- mybatis generator生成文件大小写问题
mybatis generator插件中,如果 mysql数据表中的字段是用下划线划分的(个人一般都是喜欢这么创建表的字段,如:company_name),那么生成的Vo中会自动对应为companyN ...