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 ...
随机推荐
- 什么?又是404!趣图助你理解HTTP状态码~
HTTP状态码(一): 注释: 301—永久移动.被请求的资源已被永久移动位置: 302—请求的资源现在临时从不同的 URI 响应请求: 305—使用代理.被请求的资源必须通过指定的代理才能被访问 ...
- 【Geek软技能】程序员,为什么写不好一份简历?
一份好简历会是一份好工作的开端. 为什么?沧海也会遗珠 简历,是如此重要,它是获得一份满意工作的敲门砖,但不同的简历敲门的声响可不同. 但很多时候简历给人的感觉也似乎微不足道,因为没有人会真正细致 ...
- 阿里云物联网平台体验(树莓派+Nodejs篇)
我们在<阿里云物联网平台体验(树莓派+python篇)>里,写了通过Python语言开发云到端的物联网程序,本篇文章将介绍通过nodejs来实现类似功能. 同样在阿里云官方文档里已经有了一 ...
- Linux-进程描述符 task_struct 详解
为了描述控制进程的运行,系统中存放进程的管理和控制信息的数据结构称为进程控制块 PCB(Process Control Block),它是进程实体的一部分,是操作系统中最重要的记录性数据结构.它是进程 ...
- sql 有条件计数
select InstitutionID=LEFT(InstitutionID,9), Irregularities_Type=sum(CASE WHEN Irregularities_Type> ...
- Mssql Server2005中更改sa的用户名的多种方法
mssql安装上去时默认就是sa用户,大多数用户都会一直使用sa这个用户,这样数据库就存在很大的安全问题了,如果我们能把sa用户名修改,这样安全级别又高了一层哦,下面我们来看修改sa用户名的办法. ...
- Typora的使用
Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式,其目标是实现易读易写.我刚刚接触一款简单高效的Markdown编辑器–Typora, ...
- 织梦dedecms移动版设置二级域名的方法 织梦如何设置m.开头的域名
dedecms/' target='_blank'>织梦dedecms建站系统自从2015.06.18号升级后,系统增加了最强的手机站功能,模板与PC模板分开,标签90%类似,数据同步,很牛很强 ...
- hdoj:2061
#include <iostream> #include <string> using namespace std; int main() { int n,k; double ...
- ThinkPHP 文件上传到阿里云OSS上(干货)
参考:http://www.thinkphp.cn/extend/789.html 1.前往阿里云github下载SDK包:https://github.com/aliyun/aliyun-oss-p ...