暴力。

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

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

#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. CSLA .NET是一个.NET软件开发框架

    CSLA .NET是一个.NET软件开发框架,帮助开发者“为Windows.Web.面向服务和工作流等应用构建强大和可维护的业务逻辑层”. CSLA是Component-based, Scalable ...

  2. Elmah错误日志工具

    Elmah错误日志工具 Exception 对于异常的处理,以前基本就是跳转到一个自定义的错误页面,觉得这样不错挺友好的.同时还是需要记录下来这些异常,才能进一步的进行修改. 怎么去记录这些错误信息呢 ...

  3. MVC4中使用SignalR

    MVC4中使用SignalR 前言 周末在偶尔翻阅微软官网的时候看到Getting Started with SignalR and MVC 4此篇文章,知道了signalr这个东西,貌似这个出来很长 ...

  4. [每日一题] OCP1z0-047 :2013-07-22 group by 子句

    这道题就是考where group by having的顺序... 答案A不正确:where应该放在group by前面 答案B不正确:having子句是用多行函数(sum,avg,max,min,c ...

  5. 使用Bundle在Activity之间交换数据

    一:在main.xml文件中设置布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...

  6. [置顶] C语言中各种数据类型的长度 sizeof char, short, int, long, long long

    这些数据类型的sizeof具体长度依赖于编译器和操作系统(32-bit or 64-bit) 1: 首先,参见c99标准 标准中没有定义这些数据类型的长度,而是定义了这些数据类型能表达的大小范围的最小 ...

  7. [Python]根据地址从maps文件中找相应的库名

    /proc/PID/maps提供了进程的memory layout,下面脚本根据给定地址找出相应的库名: #!/usr/bin/python from __future__ import print_ ...

  8. java参数传递(值传递还是引用传递)

    Java中的参数传递机制一直以来大家都争论不休,究竟是“传值”还是“传址(传引用)”,争论的双方各执一词,互不相让.不但“菜鸟”们一头雾水,一些“老鸟”也只知道结果却说不出所以然来.我相信看过下面的内 ...

  9. 结构-行为-样式-angularJs 指令解决IE下无PlaceHolder的问题

    最近项目开发的时候遇到一个头疼的问题,在测试IE兼容性的时候,发现placeholder在IE下无效.查网上说也是有各种解决方案,但是都不是我想要的,于是决定自己写一个.思路:placeHolder是 ...

  10. ionic2环境搭建与hello word

    一.环境搭建 需要安装配置以下组件,具体参考:Cordova环境搭建, 我的版本信息如下: 这里要特别注意,node版本,ionic2需要 大于v6 ,而不是0.xx版本,否则会不支持报错. 二.设置 ...