暴力。

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

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

#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. MVC 4 插件化架构简单实现

    转ASP.NET MVC 4 插件化架构简单实现-思路篇   用过和做过插件的都会了解插件的好处,园子里也有很多和讨论,但大都只些简单的加载程序集什么的,这里主要讨论的就是使用 ASP.NET MVC ...

  2. URLDecoder: Incomplete trailing escape (%) pattern

    在使用URLDecoder对字符串进行解码的时候 报以下异常信息: Exception in thread "main" java.lang.IllegalArgumentExce ...

  3. Excel 自定义函数

    浅谈Excel开发:四 Excel 自定义函数   我们知道,Excel中有很多内置的函数,比如求和,求平均,字符串操作函数,金融函数等等.在有些时候,结合业务要求,这些函数可能不能满足我们的需求,比 ...

  4. synchronized和volatile的使用

    synchronized和volatile的使用 一步一步掌握线程机制(三)---synchronized和volatile的使用 现在开始进入线程编程中最重要的话题---数据同步,它是线程编程的核心 ...

  5. 测试HashTable、Collections.synchronizedMap和ConcurrentHashMap的性能

        对于map的并发操作有HashTable.Collections.synchronizedMap和ConcurrentHashMap三种,到底性能如何呢? 测试代码: package com. ...

  6. struts2中token的令牌机制

    通常在普通的操作当中,我们不需要处理重复提交的,而且有很多方法来防止重复提交.比如在登陆过程中,通过使用redirect,可以让用户登陆之上重定向到后台首页界面,当用户刷新界面时就不会触发重复提交了. ...

  7. 传统的MVC模式

    对于MVC模式,我们可以将可视化UI呈现,UI处理逻辑和业务逻辑分别定义在View,Controller,和Model中. 可视化UI呈现->View UI处理逻辑->Controller ...

  8. Dom4j下载及使用Dom4j读写XML简介

    sitinspring(如坐春风)原创,转载请注明作者及出处. 要使用dom4j读写XML文档,需要先下载dom4j包,dom4j官方网站在 http://www.dom4j.org/目前最新dom4 ...

  9. 写一些脚本的心得总结系列第4篇-------从数据库同步到redis

    5.从数据库同步到redis的. redis把数据放内存里,读取都非常方便,也提供了远超memcache的丰富数据结构.下面我举2个例子,比如1)把数据从数据库写入到redis: <?php $ ...

  10. Android 动态监听网络 断网重连

    需求: 网络连接断开 弹出popupwindow 当前网络连接断开 网络恢复时popupwindow 消失重新请求网络. 需求描述完毕 上一张帅图 思路:广播 发送及时消息 断网flag  popup ...