题目链接:

  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. htmlentities() 函数

    Definition and Usage定义和用法 The htmlentities() function converts characters to HTML entities.htmlentit ...

  2. Myeclipse快捷键的设置

  3. ios进行打包

    原文转载:http://blog.csdn.net/azhou_hui/article/details/9058677   公司刚搞了个299美刀的仅提供真机测试的企业账号,这个不需要添加设备ID,而 ...

  4. [转]dos命令 cd命令使用说明[图文说明]

    Cddir(change directory,可以缩写为cd),其功能是显示当前目录的名称,或更改当前的目录. 应用时公带一个驱动器号(如: cd c:)在命令行cmd中输入 cd /? 可显示帮助信 ...

  5. opencv有关错误及解决办法

    1.载入图片时内存溢出情况,如图: 分析及解决办法:因为载入的图片太大,导致内存溢出.所以更换小一点的图片就行了. 2.

  6. 导入Android工程源码出现乱码问题的解决方法

    可以尝试着从以下三个方法进行调试,一般情况下会完美解决的: 1.windows->Preferences->General->Content Types->Text->J ...

  7. placeholder调整颜色

    placeholder需要设定以下样式: ::-webkit-input-placeholder { /* WebKit browsers */ color: #999; } :-moz-placeh ...

  8. OC文件操作(1)

    1.文件的浅度遍历与深度遍历: //NSFileManager * fm = [[NSFileManager alloc]init];//创建文件管理器 //第一步创建一个文件管理器 NSError ...

  9. 《uname命令》-linux命令五分钟系列之五

    本原创文章属于<Linux大棚>博客. 博客地址为http://roclinux.cn. 文章作者为roc 希望您能通过捐款的方式支持Linux大棚博客的运行和发展.请见“关于捐款” == ...

  10. U盘美化(更换U盘logo和页面背景软件)

    U盘内新建txt文本后,输入 [autorun] ICON=ooopic_1459309050.ico 保存的文件名包括后缀更改为autorun.inf 必须为icon图标