Fish’s mission
Fish’s mission 也就是求一个坐标到各个食堂的距离和最小,随机化做应该也是可以的。标程用的方法是利用单调性,不断尝试四个方向,二分的方法做的。实际上就是蚁群退火算法。
#include <cmath>
#include <cstdio>
#define pi acos(-1.0) struct Point{
double x,y;
Point(){}
Point(double a,double b){
x=a,y=b;
}
}point[]; double pt_distance(const Point &p1,const Point &p2){
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
} double get_all_dis(const Point &p,int n){
double ans=0.0;
for (int i=; i<n; i++) ans+=pt_distance(point[i],p);
return ans;
} int main() {
int n;
while (~scanf("%d",&n)){
for (int i=; i<n; i++)
scanf("%lf%lf",&point[i].x,&point[i].y);
Point st=point[];
double step=,mind=get_all_dis(st,n);
while (step>0.0002){
int ok=;
while (ok){
Point tmp,nt;
double t;
ok=,nt=st; tmp=Point(st.x,st.y+step);
t=get_all_dis(tmp,n);
if (t<mind) mind=t,ok=,nt=tmp; tmp=Point(st.x,st.y-step);
t=get_all_dis(tmp,n);
if (t<mind) mind=t,ok=,nt=tmp; tmp=Point(st.x+step,st.y);
t=get_all_dis(tmp,n);
if (t<mind) mind=t,ok=,nt=tmp; tmp=Point(st.x-step,st.y);
t=get_all_dis(tmp,n);
if (t<mind) mind=t,ok=,nt=tmp; st=nt;
}
step=step/2.0;
}
printf("%.3lf\n",mind);
}
return ;
}
Fish’s mission的更多相关文章
- Java 性能分析工具 , 第 3 部分: Java Mission Control
引言 本文为 Java 性能分析工具系列文章第三篇,这里将介绍如何使用 Java 任务控制器 Java Mission Control 深入分析 Java 应用程序的性能,为程序开发人员在使用 Jav ...
- “You couldn’t see my tears cause I am in the water.“ Fish said to water.“But I could feel your tears cause you are in my heart..“ Answered water.
“You couldn’t see my tears cause I am in the water.“ Fish said to water.“But I could feel your tears ...
- JavaScript、jQuery、fish的遍历方法(each、forEach)总结
起因 在工作中,需要在遍历的dom中找到第一个并做下操作然后退出遍历,我首先想到了用each方法,但由于无论是公用的jQuery组件还是公司的fish组件.我都忘记了怎么去退出遍历,所以就有了这篇帖子 ...
- 类的继承和多态性-编写Java应用程序,定义Animal类,此类中有动物的属性:名称 name,腿的数量legs,统计动物的数量 count;方法:设置动物腿数量的方法 void setLegs(),获得腿数量的方法 getLegs(),设置动物名称的方法 setKind(),获得动物名称的方法 getKind(),获得动物数量的方法 getCount()。定义Fish类,是Animal类的子类,
编写Java应用程序,定义Animal类,此类中有动物的属性:名称 name,腿的数量legs,统计动物的数量 count;方法:设置动物腿数量的方法 void setLegs(),获得腿数量的方法 ...
- java基础—继承题目:编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish
编写一个Animal类,具有属性:种类:具有功能:吃.睡.定义其子类Fish package zhongqiuzuoye; public class Animal { //属性 private Str ...
- 编写Java应用程序,定义Animal类,此类中有动物的属性:名称 name,腿的数量legs,统计动物的数量 count;方法:设置动物腿数量的方法 void setLegs(),获得腿数量的方法 getLegs(),设置动物名称的方法 setKind(),获得动物名称的方法 getKind(),获得动物数量的方法 getCount()。定义Fish类,是Animal类的子类,统计鱼的数量 co
package com.hanqi.test; public class Animal { private String name; private int legs; private int cou ...
- 正则表达式30分钟入门:http://deerchao.net/tutorials/regex/regex.htm#mission
http://deerchao.net/tutorials/regex/regex.htm#mission
- FZU 1608 Huge Mission(线段树)
Problem 1608 Huge Mission Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description Oaiei ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6
#1228 : Mission Impossible 6 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You must have seen the very famou ...
随机推荐
- Delphi 把字符串读到流中的操作。
var FReQuestM := TMemoryStream FReQuestM.Write(PChar(FcVoucherXML)^, Length(FcVoucherXML)); 这样就读到流中了 ...
- 自定义xcode文件模板
下面两个路径都可以用于放模板文件 1. /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Template ...
- [置顶] js对象
js中,一切事物都是对象.对象是一切的基础. 而具体到某一个对象时. 对象则是包含一组变量和函数的集合实例 我们先来中体会下je对象的全局. 接下来就具体揭开这个对象的面纱吧 ja对象分类 Funct ...
- c语言通过时间种子产生随机数并选出最大值以及下标
1 #include <stdio.h> #include <stdlib.h> #include <time.h> //2016 10 10 void main( ...
- php中strstr、strrchr、substr、stristr四个函数的区别总结
php中strstr.strrchr.substr.stristr四个函数的区别总结 投稿:junjie 字体:[增加 减小] 类型:转载 时间:2014-09-22我要评论 这篇文章主要介绍了php ...
- JavaScript 中的正常任务与微任务
正常情况下,JavaScript的任务是同步执行的,即执行完前一个任务,然后执行后一个任务.只有遇到异步任务的情况下,执行顺序才会改变. 这时,需要区分两种任务:正常任务(task)与微任务(micr ...
- 关于C语言中的inline
在c中,为了解决一些频繁调用的小函数大量消耗栈空间或是叫栈内存的问题,特别的引入了inline修饰符,表示为内联函数.栈空间就是指放置程式的局部数据也就是函数内数据的内存空间,在系统下,栈空间是有限的 ...
- 解决android自带textview右侧文字不能对齐的问题
package com.sixin.view; import android.content.Context; import android.graphics.Canvas; import andro ...
- keydown和keypress
常见的键盘事件是keyup和keydown.淡蓝就经常用 document.onkeyup = function (e) { if ((e.keyCode || e.which) === 13) // ...
- RegExp子模式- "()"
读书笔记 把JavaScript权威指南拿出来瞅瞅,正巧看到了第十章 正则表达式的模式匹配 最初接触js的时候,基本上都是在做验证.什么数字验证.命名验证.身份证格式验证.电话号码验证.都是用正则表达 ...