暴力。

每个人找到一个入口,也就是从回收站到这个入口走的路程由人的位置到入口的路程来替代。

因此,只要找两个人分别从哪里入口就可以了。注意:有可能只要一个人走,另一人不走。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
double ax,ay,bx,by,tx,ty;
struct X{ double x,y;int id; }s[maxn];
int n; bool cmp1(X a,X b)
{
return sqrt((a.x-ax)*(a.x-ax)+(a.y-ay)*(a.y-ay))-sqrt((a.x-tx)*(a.x-tx)+(a.y-ty)*(a.y-ty))
<
sqrt((b.x-ax)*(b.x-ax)+(b.y-ay)*(b.y-ay))-sqrt((b.x-tx)*(b.x-tx)+(b.y-ty)*(b.y-ty));
} bool cmp2(X a,X b)
{
return sqrt((a.x-bx)*(a.x-bx)+(a.y-by)*(a.y-by))-sqrt((a.x-tx)*(a.x-tx)+(a.y-ty)*(a.y-ty))
<
sqrt((b.x-bx)*(b.x-bx)+(b.y-by)*(b.y-by))-sqrt((b.x-tx)*(b.x-tx)+(b.y-ty)*(b.y-ty));
} bool cmp3(X a,X b)
{
return a.id<b.id;
} int a[maxn],sz; int main()
{
scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty); scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lf%lf",&s[i].x,&s[i].y),s[i].id=i; if(n==)
{
double ans;
ans=min(sqrt((ax-s[].x)*(ax-s[].x)+(ay-s[].y)*(ay-s[].y))+
sqrt((tx-s[].x)*(tx-s[].x)+(ty-s[].y)*(ty-s[].y))
,
sqrt((bx-s[].x)*(bx-s[].x)+(by-s[].y)*(by-s[].y))+
sqrt((tx-s[].x)*(tx-s[].x)+(ty-s[].y)*(ty-s[].y))
);
printf("%.6lf\n",ans);
return ;
} double ans=;
double g=;
for(int i=;i<=n;i++) g=g+*sqrt((s[i].x-tx)*(s[i].x-tx)+(s[i].y-ty)*(s[i].y-ty)); sort(s+,s++n,cmp1);
ans=min(ans,
g+sqrt((s[].x-ax)*(s[].x-ax)+(s[].y-ay)*(s[].y-ay))
-sqrt((s[].x-tx)*(s[].x-tx)+(s[].y-ty)*(s[].y-ty)));
for(int i=;i<=min(n,);i++) a[sz++]=s[i].id; sort(s+,s++n,cmp2);
ans=min(ans,
g+sqrt((s[].x-bx)*(s[].x-bx)+(s[].y-by)*(s[].y-by))
-sqrt((s[].x-tx)*(s[].x-tx)+(s[].y-ty)*(s[].y-ty)));
for(int i=;i<=min(n,);i++) a[sz++]=s[i].id; sort(s+,s++n,cmp3); for(int i=; i<sz; i++)
{
for(int j=; j<sz; j++)
{
if(a[j]==a[i]) continue; double tmp=g;
tmp=tmp+sqrt((s[a[i]].x-ax)*(s[a[i]].x-ax)+(s[a[i]].y-ay)*(s[a[i]].y-ay));
tmp=tmp+sqrt((s[a[j]].x-bx)*(s[a[j]].x-bx)+(s[a[j]].y-by)*(s[a[j]].y-by));
tmp=tmp-sqrt((s[a[i]].x-tx)*(s[a[i]].x-tx)+(s[a[i]].y-ty)*(s[a[i]].y-ty));
tmp=tmp-sqrt((s[a[j]].x-tx)*(s[a[j]].x-tx)+(s[a[j]].y-ty)*(s[a[j]].y-ty)); ans=min(ans,tmp);
}
}
printf("%.6lf\n",ans);
return ;
}

CodeForces 671A Recycling Bottles的更多相关文章

  1. 【模拟】Codeforces 671A Recycling Bottles

    题目链接: http://codeforces.com/problemset/problem/671/A 题目大意: A和B在一张二维平面上,平面上有N个垃圾,垃圾桶只有一个在T,问把所有垃圾全扔进垃 ...

  2. Codeforces 671A Recycling Bottles(贪心+思维)

    题目链接:http://codeforces.com/problemset/problem/671/A 题目大意:给你两个人的位置和一个箱子的位置,然后给出n个瓶子的位置,要求让至少一个人去捡瓶子放到 ...

  3. codeforces 672C - Recycling Bottles 贪心水题

    感觉很简单,就是讨论一下 #include <stdio.h> #include <string.h> #include <algorithm> #include ...

  4. Codeforces Recycling Bottles 模拟

    C. Recycling Bottles time limit per test: 2 seconds memory limit per test: 256 megabytes input: stan ...

  5. Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力

    A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...

  6. Codeforces Round #352 (Div. 2) C. Recycling Bottles 贪心

    C. Recycling Bottles   It was recycling day in Kekoland. To celebrate it Adil and Bera went to Centr ...

  7. codeforces 352 div 2 C.Recycling Bottles 贪心

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. Codeforces 671 A——Recycling Bottles——————【思维题】

     Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #352 (Div. 2) C. Recycling Bottles

      C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. [Usaco2008 Feb]Meteor Shower流星雨[BFS]

    Description 去年偶们湖南遭受N年不遇到冰冻灾害,现在芙蓉哥哥则听说另一个骇人听闻的消息: 一场流星雨即将袭击整个霸中,由于流星体积过大,它们无法在撞击到地面前燃烧殆尽, 届时将会对它撞到的 ...

  2. windbg Symbol file path

    SOS是一个调试器扩展,用于调试.NET应用程序.它提供了一组非常丰富的命令,这些命令使开发人员可以对CLR进行深入分析,并且有助于找出应用程序中各种复杂错误的原因.   由于SOS能够提供CLR内部 ...

  3. MongoDB:利用官方驱动改装为EF代码风格的MongoDB.Repository框架 四

    本次改动主要实现MongoGridFS功能.实现方式主要使用了MongoGridFS和MongoGridFSFileInfo两个类. 设计思路:定义一个IMongoFile接口并继承IEntity,以 ...

  4. [转]Iphone m3u8 segmenter from ffmpeg for video streaming

    源地址:http://lukasz.cepowski.com/devlog/30,iphone-m3u8-segmenter-from-ffmpeg-for-video-streaming Recen ...

  5. 《C++游戏开发》笔记十三 平滑过渡的战争迷雾(一) 原理:Warcraft3地形拼接算法

    本系列文章由七十一雾央编写,转载请注明出处.  http://blog.csdn.net/u011371356/article/details/9611887 作者:七十一雾央 新浪微博:http:/ ...

  6. jquery实现城市选择器效果(二级联动)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. JQ与AJAX 省市区三级联动下拉框

    用于初学者学习基本的联动下拉框,废话不多说,见代码 首先看控制器里的3个下拉框对应代码: public ActionResult GetProvinceList() { ProvinceReposit ...

  8. struts2图片显示

    struts2图片显示即是文件下载 一.配置struts.xml struts.xml中配置stream结果类型,并配置contentType.inputName.contentDisposition ...

  9. MongoDB的一些用法(转藏)

    MongoDB是目前工作中经常使用到的NoSQL数据库. 本博客只记录相关理论知识和技巧,涉及到实践的部分都会单开Blog来记录实践过程. ------------------------------ ...

  10. .net中获取图像缩略图的函数GetThumbnailImage

    关于.net中获取图像缩略图的函数GetThumbnailImage的一些认识. 在很多图像软件中,打开一幅图像的时候都会显示其缩略图,在看图软件中这样的需求更为常见.如何快速的获取缩略图的信息并提供 ...