bzoj3689 luogu p1337
2015-11-13 18:16
155 查看
人生第一道退火 (虽然调了一个上午然后删了几个变量居然A了雾。 带权值费马点? 反正直接暴力退火就是了 然后不停调常数我可怜的ratioQAQ 附代码:#include #include #include #include #include using namespace std; struct node{ double x,y,g; }p[10201]; int n; node ans; doubleminans=6666666666666666ll; double dis(nodea,node b) { returnsqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double RA() { returnrand()00/1000.0; } double calc( node t) { int i; double res=0; for(i=1;i<=n;i++) res+=dis(p[i],t)*p[i].g; if(res minans=res,ans=t; return res; } voidSA(double T) { int i;node ne; node now=ans; while(T>0.001) { ne.x=now.x+T*(RA()*2-1 ); ne.y=now.y+T*(RA()*2-1 ); doublead=calc(now)-calc(ne); if(ad>0||exp(ad/T)>RA()) now=ne; T*=0.993; } for(i=1;i<=1000;i++) { node ne; ne.x=ans.x+T*(RA()*2-1); ne.y=ans.y+T*(RA()*2-1); calc(ne); } } int main() { int i; srand(233666); scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].g); ans.x+=p[i].x; ans.y+=p[i].y; } ans.x/=n; ans.y/=n; SA(1000000); //calc((node){0.570,1}); printf("%.3lf%.3lf\n",ans.x,ans.y); return 0; } |
相关文章推荐
- 【转】C#类似Jquery的html解析类HtmlAgilityPack基础类介绍及运用
- Unity3d 鼠标拣选小功能集合
- Week7阅读笔记
- WebView 正确设置cookie 的方法
- 写给初学git的童鞋
- 上传APP时遇到的问题
- codevs1356 bzoj2746 jsoi2012
- codevs 1033蚯蚓的游戏 (最大费用流
- codevs 1227 方格取数 网络流
- Poj1416
- Poj3020
- codevs1022
- 堆模版
- 后缀数组
- 洛谷p1160 双向链表
- 几何求面积
- 关于凸包:grahman scan
- 计算几何————洛谷P1222 三角形
- 图形的绘制(包括线段 圆形 矩形等) swift编写
- Merge k Sorted Lists