题目链接:

  http://codeforces.com/problemset/problem/671/A

题目大意:

  A和B在一张二维平面上,平面上有N个垃圾,垃圾桶只有一个在T,问把所有垃圾全扔进垃圾桶最少走多远。一次只能拿一个垃圾。允许一个人走另一个人停下来。

  (1 ≤ n ≤ 100 000)  (0 ≤ xi, yi ≤ 109)

题目思路:

  【模拟】

  因为每次只能携带一个垃圾,大部分垃圾都是人扔完上一个垃圾后,从垃圾桶出发去捡的。

  而最多有两个垃圾不是被人从垃圾桶出发完再扔到垃圾桶。

  可以先将答案算作都从垃圾桶开始往返捡的距离,再枚举哪一个垃圾被人直接走过去捡能优化答案。注意不要让两个人都选择同一个垃圾。

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 100004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
double anss;
struct xxx
{
LL x,y;
double disa,disb,dist;
}q[N],a,b,t;
double dis(xxx aa,xxx bb)
{
return sqrt(sqr(aa.x-bb.x)+sqr(aa.y-bb.y));
}
bool cmp(xxx aa,xxx bb)
{
return aa.dist<bb.dist;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,ma,mb;
double ax,ay,bx,by,z;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
while(~scanf("%I64d",&a.x))
// while(~scanf("%d",&n))
{
anss=;ay=by=;
scanf("%I64d%I64d%I64d%I64d%I64d",&a.y,&b.x,&b.y,&t.x,&t.y);
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%I64d%I64d",&q[i].x,&q[i].y);
q[i].disa=dis(a,q[i]);
q[i].disb=dis(b,q[i]);
q[i].dist=dis(t,q[i]);
}
sort(q+,q++n,cmp);
anss=q[].dist+q[].dist;
ax=q[].dist-q[].disa;
bx=q[].dist-q[].disb;
ma=mb=;
for(i=;i<=n;i++)
{
anss+=q[i].dist+q[i].dist;
z=q[i].dist-q[i].disa;
if(ax<z)
{
ay=max(ax,ay);
ax=z;
ma=i;
}
else ay=max(ay,z);
z=q[i].dist-q[i].disb;
if(bx<z)
{
by=max(bx,by);
bx=z;
mb=i;
}
else by=max(by,z);
}
if(ma!=mb)z=ax+bx;
else z=max(ax+by,bx+ay);
z=max(z,ax);
z=max(z,bx);
printf("%.12lf\n",anss-z);
}
return ;
}
/*
// //
*/

【模拟】Codeforces 671A Recycling Bottles的更多相关文章

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

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

  2. CodeForces 671A Recycling Bottles

    暴力. 每个人找到一个入口,也就是从回收站到这个入口走的路程由人的位置到入口的路程来替代. 因此,只要找两个人分别从哪里入口就可以了.注意:有可能只要一个人走,另一人不走. #pragma comme ...

  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. 10.7 noip模拟试题

    楼[问题背景]zhx 为他的妹子造了一幢摩天楼.[问题描述]zhx 有一幢摩天楼. 摩天楼上面有 M 个观光电梯,每个观光电梯被两个整数

  2. ASP 调用dll(VB)及封装dll实例

    ASP调用dll及封装dll实例,封装为dll可以提供运行效率,加密代码. 打开VB6,新建ActiveX DLL 2.在工程引用中加入Microsoft Active Server Pages Ob ...

  3. UTF-8和GBK有什么区别?

    字符均使用双字节来表示,只不过为区分中文,将其最高位都定成1. 至于UTF-8编码则是用以解决国际上字符的一种多字节编码,它对英文使用8位(即一个字节),中文使用24位(三个字节)来编码.对于英文字符 ...

  4. html招聘简历解析并入库测试

    1.解析4天,一天用来熟悉Jsoup 2.入库,需要熟悉什么样的格式代码可以入库,将自己解析好的代码转为指定格式.总体框架的构建, 如何执行,需要读他人写的代码(很费时间).4天,包括晚上九点加班三天 ...

  5. javascript——集合类

    /** * Created by Administrator on 2015/4/14. */ function Set() { this.values = {}; this.n = 0; this. ...

  6. 关于Asp.Net中避免用户连续多次点击按钮,重复提交表单的处理

    Web页面中经常碰到这类问题,就是客户端多次点击一个按钮或者链接,导致程序出现不可预知的麻烦. 客户就是上帝,他们也不是有意要给你的系统造成破坏,这么做的原因很大一部分是因为网络慢,点击一个操作之后, ...

  7. 在CentOS 7中轻松安装Atomic应用(atomicapp)

    sudo yum install docker atomic etcd kubernetes sudo systemctl enable docker.service sudo systemctl s ...

  8. HTML5 Canvas画数字时钟

    先不说废话,没代码算个蛋. 一些地方注释都写得比较清楚,不过这只是部分,因为只有秒针,但是时针,分针的逻辑都是一致的. 代码中有些坐标不知道为什么较不准,看看就好

  9. DedeCMS时间格式

    时间格式 {dede:field name='pubdate' function='strftime("%Y年%m月%d日 %H:%M:%S","@me")' ...

  10. 项目知识点.Part3

    内存管理: 基本数据类型或者Core Foundation对象都没有引用计数 主线程会自动创建释放池,子线程需要手动创建释放池. 具体的区别:http://www.cnblogs.com/langti ...