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的更多相关文章

  1. Java 性能分析工具 , 第 3 部分: Java Mission Control

    引言 本文为 Java 性能分析工具系列文章第三篇,这里将介绍如何使用 Java 任务控制器 Java Mission Control 深入分析 Java 应用程序的性能,为程序开发人员在使用 Jav ...

  2. “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 ...

  3. JavaScript、jQuery、fish的遍历方法(each、forEach)总结

    起因 在工作中,需要在遍历的dom中找到第一个并做下操作然后退出遍历,我首先想到了用each方法,但由于无论是公用的jQuery组件还是公司的fish组件.我都忘记了怎么去退出遍历,所以就有了这篇帖子 ...

  4. 类的继承和多态性-编写Java应用程序,定义Animal类,此类中有动物的属性:名称 name,腿的数量legs,统计动物的数量 count;方法:设置动物腿数量的方法 void setLegs(),获得腿数量的方法 getLegs(),设置动物名称的方法 setKind(),获得动物名称的方法 getKind(),获得动物数量的方法 getCount()。定义Fish类,是Animal类的子类,

    编写Java应用程序,定义Animal类,此类中有动物的属性:名称 name,腿的数量legs,统计动物的数量 count;方法:设置动物腿数量的方法 void setLegs(),获得腿数量的方法 ...

  5. java基础—继承题目:编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish

    编写一个Animal类,具有属性:种类:具有功能:吃.睡.定义其子类Fish package zhongqiuzuoye; public class Animal { //属性 private Str ...

  6. 编写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 ...

  7. 正则表达式30分钟入门:http://deerchao.net/tutorials/regex/regex.htm#mission

    http://deerchao.net/tutorials/regex/regex.htm#mission

  8. FZU 1608 Huge Mission(线段树)

    Problem 1608 Huge Mission Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description Oaiei ...

  9. ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6

    #1228 : Mission Impossible 6 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You must have seen the very famou ...

随机推荐

  1. Linux 内存管理知识学习总结

    现在的服务器大部分都是运行在Linux上面的,所以,作为一个程序员有必要简单地了解一下系统是如何运行的.对于内存部分需要知道: 地址映射 内存管理的方式 缺页异常 先来看一些基本的知识,在进程看来,内 ...

  2. IIS 问题解决

    一.网站发布后 报500错误 解决办法:重新向iis注册framwork: 二.试图加载格式不正确的程序.(Exception from HRESULT: 0x8007000B) 解决办法:对应应用程 ...

  3. Hadoop,HBase集群环境搭建的问题集锦(四)

    21.Schema.xml和solrconfig.xml配置文件里參数说明: 參考资料:http://www.hipony.com/post-610.html 22.执行时报错: 23., /comm ...

  4. hdu 4756 Install Air Conditioning

    非正规做法,一个一个的暴,减一下枝,还得采用sort,qsort居然过不了…… #include <cstdio> #include <cmath> #include < ...

  5. Entity Framework - Func引起的数据库全表查询

    原文:http://www.cnblogs.com/dudu/archive/2012/04/01/enitity_framework_func.html 使用 Entity Framework 最要 ...

  6. 使用VTemplate模板引擎动态生成订单流程图

    1.VTemplate模板引擎的简介 VTemplate模板引擎也简称为VT,是基于.NET的模板引擎,它允许任何人使用简单的类似HTML语法的模板语言来引用.NET里定义的对象.当VTemplate ...

  7. (转)CSS 禁止浏览器滚动条的方法

    1.完全隐藏 在里加入scroll="no",可隐藏滚动条:    这个我用的时候完全没效果,不知道是什么原因!不过好多人说这么用可以,大概是用的位置不一样吧   2.在不需要时隐 ...

  8. LinkedList : 双向链表与实现

    所谓双向链表: (由此图可见老夫深厚的画功) 链表,就是由一个一个的节点连接组成. 在这里,每一个节点都是由三部分组成:上一个节点.当前节点的元素.下一个节点 当链表中只有一个节点的时候,这个节点指向 ...

  9. java HashMap的原理

    HashMap的数据结构: 在java编程语言中,最基本的结构就是两种,一个是数组,另外一个是模拟指针(引用),所有的数据结构都可以用这两个基本结构来构造的,HashMap也不例外.HashMap实际 ...

  10. C++深层复制解决指针悬挂

    代码: #include <iostream> #include <cstring> using namespace std; class mystring{ public: ...