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 ...
随机推荐
- Fiddler 的几个用法
原文地址:http://wenku.baidu.com/link?url=VGYtzCpGdWzyvGFAIgCVS_KbSh5Oemd4rRYqyJORDchy4jxtEiRNWbp0tqPtlBR ...
- c++命名空间using
#include<iostream> namespace run1 { ; } namespace run2 { ; void show() { std::cout << x ...
- Java常见内存溢出异常分析(OutOfMemoryError)
原文转载自:http://my.oschina.net/sunchp/blog/369412 1.背景知识 1).JVM体系结构 2).JVM运行时数据区 JVM内存结构的相关可以参考: http:/ ...
- 第23讲 UI_布局 之相对布局
第23讲 UI_布局 之相对布局 .RelativeLayout(相对布局): RelativeLayout(相对布局)是指组件的位置总是相对兄弟组件.父容器来决定的(相对位置),如某个组件的左边右边 ...
- Fiddler 抓取eclipse中的请求
Fiddler 抓取eclipse中的请求 代码中添加 System.setProperty("http.proxySet", "true"); System. ...
- MVC 控制器详解
Controller: Controllers 文件夹包含负责处理用户输入和响应的控制器类. MVC 要求所有控制器的名称必须以 "Controller" 结尾. 控制器的职责: ...
- 【转】10分钟了解设计模式(C#)
10分钟了解设计模式(C#) 最近把<大话设计模式>重温了下(看完序才知道原来作者是也是博客园园友,这本书的最早博客版本在这里).体会最深的就是面向接口编程的重要性,如何在自己的项目中进行 ...
- HDU 1027 Ignatius and the Princess II 选择序列题解
直接选择序列的方法解本题,可是最坏时间效率是O(n*n),故此不能达到0MS. 使用删除优化,那么就能够达到0MS了. 删除优化就是当须要删除数组中的元素为第一个元素的时候,那么就直接移动数组的头指针 ...
- Oracle - SQL 错误: ORA-00917: 缺失逗号
ORACLE SQL语句中int型插入数据库时,不要加引号.
- VS2010 rdlc 被除数为0 显示错误号
=Sum(Fields!ROCKNUM.Value/Fields!SEND.Value*100) 当Fields!SEND.Value为0或者空时,显示错误号 修改: =IIF(isnothing(F ...