poj 2420 A Star not a Tree?
2016-04-25 10:11
429 查看
萌萌哒传送门
基本上代码和黄学长的一毛一样
模拟退火
主要是生成新状态和评价函数搞不清怎么弄。。
自己YY的一个每次跑出来答案不一样T_T
有人说是以要移动的点为中心,以2t为长的正方形中的随机一个移动位置来求最优值。。
看了代码发现他那个讲道理也不算模拟退火,因为没有概率接受非更优解。。
然而为甚么黄学长在生成新状态没有用随机化。。。
最后得出结论:大神思路太diao吾等蒟蒻只配%%%
代码(有谁看懂了给解释下好么。。):
萌萌哒传送门2
基本上代码和黄学长的一毛一样
模拟退火
主要是生成新状态和评价函数搞不清怎么弄。。
自己YY的一个每次跑出来答案不一样T_T
有人说是以要移动的点为中心,以2t为长的正方形中的随机一个移动位置来求最优值。。
看了代码发现他那个讲道理也不算模拟退火,因为没有概率接受非更优解。。
然而为甚么黄学长在生成新状态没有用随机化。。。
最后得出结论:大神思路太diao吾等蒟蒻只配%%%
代码(有谁看懂了给解释下好么。。):
#include<set> #include<map> #include<cmath> #include<ctime> #include<queue> #include<stack> #include<cstdio> #include<vector> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define g getchar() #define ll long long #define inf 0x3f3f3f3f using namespace std; inline ll read(){ ll x=0,f=1;char ch=g; for(;ch<'0'||ch>'9';ch=g)if(ch=='-')f=-1; for(;ch>='0'&&ch<='9';ch=g)x=x*10+ch-'0'; return x*f; } inline void out(ll x){ int a[25],wei=0; if(x<0)putchar('-'),x=-x; for(;x;x/=10)a[++wei]=x%10; if(wei==0){puts("0");return;} for(int j=wei;j>=1;--j)putchar('0'+a[j]); putchar('\n'); } struct re{ int x,y; }p[105]; int n; inline double sqr(double x){return x*x;} double dis(double x,double y,re p) {return sqrt(sqr(x-p.x)+sqr(y-p.y));} double getsum(double x,double y){ double tmp=0; for(int i=1;i<=n;++i)tmp+=dis(x,y,p[i]); return tmp; } int main(){ srand(time(0)); while(scanf("%d",&n)==1){ double xx=0,yy=0;double ans=1e20;double t=100000; for(int i=1;i<=n;++i){ p[i].x=read();p[i].y=read(); xx+=p[i].x;yy+=p[i].y; } xx/=n;yy/=n; ans=getsum(xx,yy); double tmp,x,y; for(;t>0.02;t*=0.9){ x=y=0; for(int i=1;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)/10000.0){ //随机化判定是否接受移动 ans=tmp;xx+=x*t;yy+=y*t; } } printf("%.0lf",ans); } }
萌萌哒传送门2
相关文章推荐
- 4月13日 项目管理师作业
- Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'x/info.plist'
- CSDN看的一些 C艹笔试题
- 如何做好网站导航的布局优化?
- linux下配置安装mongodb
- ios常用框架
- Swift---TextView用法
- Android四大组件--MediaPlayer详解(转)
- 4月11日项目管理师作业
- XML解析的三种方式(dom,sax,dom4j)
- SAP BDC(Batch Data Conversion )技术之我见
- jvm常用优化方案和方法
- Hibernate映射解析——七种映射关系
- Oracle VM + centos7.1+openstack kilo 多结点安装教程---glance的安装
- Redis-stat的安装与使用
- win7 网络和共享中心提示“依赖服务或组无法启动” 解决方法
- 深入源码分析HashSet
- ANDROID webview加载本地内容代码
- xcode7开发者账号真机调试
- 版本更新