【POJ2420】A star not a tree?
蒟蒻开始学模拟退火……
起初一直不肯学,因为毕竟玄学算法……
哎呀玄学怎么就没用呢?对不对?
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- #include<cstdlib>
- #include<cmath>
- #include<ctime>
- using namespace std;
- int n;
- double xx,yy,ans,T;
- struct Point{double x,y;}p[];
- inline double sqr(double x){return x*x;}
- inline double dis(double x,double y,Point p){
- return sqrt(sqr(x-p.x)+sqr(y-p.y));
- }
- inline double getsum(double x,double y){
- double ret=;
- for(int i=;i<=n;i++)ret+=dis(x,y,p[i]);
- return ret;
- }
- int main(){
- srand(time(NULL));
- while(~scanf("%d",&n)){
- xx=yy=;ans=1e20;T=;
- for(int i=;i<=n;i++){
- scanf("%lf%lf",&p[i].x,&p[i].y);
- xx+=p[i].x;yy+=p[i].y;
- }
- xx/=n;yy/=n;ans=getsum(xx,yy);
- double tmp,x,y;
- while(T>=0.02){
- x=y=;
- for(int i=;i<=n;i++){
- x+=(p[i].x-xx)/dis(xx,yy,p[i]);
- y+=(p[i].y-yy)/dis(xx,yy,p[i]);
- }
- tmp=getsum(xx+x*T,yy+y*T);
- if(tmp<ans){ans=tmp;xx+=x*T;yy+=y*T;}
- else if(log((tmp-ans)/T)<(rand()%)/10000.0)
- {ans=tmp;xx+=x*T;yy+=y*T;}
- T*=0.9;
- }
- printf("%.0lf\n",ans);
- }
- }
【POJ2420】A star not a tree?的更多相关文章
- 【POJ】【2420】A Star not a Tree?
模拟退火 Orz HZWER 这题的题意是在二维平面内找一点,使得这点到给定的n个点的距离和最小……0.0 模拟退火算法请戳这里 //POJ 2420 #include<ctime> #i ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【BZOJ2843】极地旅行社(Link-Cut Tree)
[BZOJ2843]极地旅行社(Link-Cut Tree) 题面 BZOJ 题解 \(LCT\)模板题呀 没什么好说的了.. #include<iostream> #include< ...
- 【BZOJ4530】大融合(Link-Cut Tree)
[BZOJ4530]大融合(Link-Cut Tree) 题面 讨厌权限题!!! Loj链接 题目描述 小强要在 N个孤立的星球上建立起一套通信系统.这套通信系统就是连接 N个点的一个树.这个树的边是 ...
- 【BZOJ1969】航线规划(Link-Cut Tree)
[BZOJ1969]航线规划(Link-Cut Tree) 题面 BZOJ 题解 删边操作 套路呀 离线读入倒过来做 变成加边操作 现在考虑怎么确定两点直接的关键路径条数 如果是一棵树,那么每条边都是 ...
- 【BZOJ4825】【HNOI2017】单旋(Link-Cut Tree)
[BZOJ4825][HNOI2017]单旋(Link-Cut Tree) 题面 题面太长,懒得粘过来 题解 既然题目让你写Spaly 那就肯定不是正解 这道题目,让你求的是最大/最小值的深度 如果有 ...
- 【BZOJ3669】【Noi2014】魔法森林(Link-Cut Tree)
[BZOJ3669][Noi2014]魔法森林(Link-Cut Tree) 题面 题目描述 为了得到书法大家的真传,小 E 同学下定决心去拜访住在魔法森林中的隐 士.魔法森林可以被看成一个包含 n ...
- 【BZOJ2049】洞穴勘测(Link-Cut Tree)
[BZOJ2049]洞穴勘测(Link-Cut Tree) 题面 题目描述 辉辉热衷于洞穴勘测. 某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别 ...
- 【BZOJ3999】[TJOI2015]旅游(Link-Cut Tree)
[BZOJ3999][TJOI2015]旅游(Link-Cut Tree) 题面 BZOJ 洛谷 题解 一道不难的\(LCT\)题(用树链剖分不是为难自己吗,这种有方向的东西用\(LCT\)不是方便那 ...
随机推荐
- [洛谷P5174]圆点
题目大意:给你$R(R\leqslant10^{14})$,求:$$\sum\limits_{x\in\mathbb{Z}}\sum\limits_{y\in\mathbb{Z}}[x^2+y^2\l ...
- [洛谷P4822][BJWC2012]冻结
题目大意:有一张$n(n\leqslant50)$个点$m(m\leqslant1000)$条边的无向图,可以使得$k$条边使得边权减半,求最短路 题解:分层图最短路 卡点:无 C++ Code: # ...
- BZOJ3998:[TJOI2015]弦论——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=3998 https://www.luogu.org/problemnew/show/P3975 对于 ...
- BZOJ2724:[Violet 6]蒲公英——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2724 输入格式 第一行两个整数n,m,表示有n株蒲公英,m次询问. 接下来一行 n 个空格分隔的整数 ...
- HDU1007:Quoit Design——题解
http://acm.hdu.edu.cn/showproblem.php?pid=1007 题目大意:给n个点,求点对最短距离/2. —————————————————————— 平面分治裸题. 暂 ...
- 【简单算法】17.字符串转整数(atoi)
题目: 实现 atoi,将字符串转为整数. 在找到第一个非空字符之前,需要移除掉字符串中的空格字符.如果第一个非空字符是正号或负号,选取该符号,并将其与后面尽可能多的连续的数字组合起来,这部分字符即为 ...
- HDU2121:Ice_cream’s world II (虚根+有向图最小生成树)
Ice_cream’s world II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Leetcode 144.二叉树的前序遍历
1.题目描述 给定一个二叉树,返回它的 前序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,2,3] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 2.解法 ...
- poj 3498 最大流
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4809 Accepted: ...
- Rsync+inotify自动同步数据
一.简介 随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐渐暴露出了很多不足. 首先,rsync在同步数据时,需要扫描所有文件后进行比对,进行差量传 ...