codeforces 352 div 2 C.Recycling Bottles 贪心
2 seconds
256 megabytes
standard input
standard output
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can carry only one bottle at once each.
For both Adil and Bera the process looks as follows:
- Choose to stop or to continue to collect bottles.
- If the choice was to continue then choose some bottle and walk towards it.
- Pick this bottle and walk to the recycling bin.
- Go to step 1.
Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles.
They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.
First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.
Then follow n lines, each of them contains two integers xi and yi (0 ≤ xi, yi ≤ 109) — position of the i-th bottle.
It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if
.
3 1 1 2 0 0
3
1 1
2 1
2 3
11.084259940083
5 0 4 2 2 0
5
5 2
3 0
5 5
3 5
3 3
33.121375178000
Consider the first sample.
Adil will use the following path:
.
Bera will use the following path:
.
Adil's path will be
units long, while Bera's path will be
units long.
题意:给你两个人,一个垃圾桶;利用人把垃圾全部进桶,使得距离最短;
思路:显然答案是sigma一个垃圾到垃圾桶距离的两倍;
求出一个人动和两个人动的差值最大的距离;
比较减去最大值;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define esp 0.00000000001
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
long double dis(long double a,long double b,long double c,long double d)
{
return sqrt((d-b)*(d-b)+(c-a)*(c-a));
}
struct is
{
long double cha;
int pos;
}a1[],b1[];
int flag[];
bool cmp(is x,is y)
{
return x.cha>y.cha;
}
int main()
{
long double a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
long double sum=;
int x;
scanf("%d",&x);
for(int i=;i<x;i++)
{
long double u,v;
cin>>u>>v;
sum+=dis(e,f,u,v)*2.0;
a1[i].cha=dis(e,f,u,v)-dis(u,v,a,b);
b1[i].cha=dis(e,f,u,v)-dis(u,v,c,d);
a1[i].pos=i;
b1[i].pos=i;
}
if(x==)
{
//printf("%f\n",sum-max(a1[0].cha,b1[0].cha));
cout << setprecision() << setiosflags(ios::scientific)<<sum-max(a1[].cha,b1[].cha)<<endl;
return ;
}
sort(a1,a1+x,cmp);
sort(b1,b1+x,cmp);
double aa,bb;
if(a1[].cha<&&b1[].cha<)
{
cout << setprecision() << setiosflags(ios::scientific)<<sum-max(a1[].cha,b1[].cha)<<endl;
return ;
}
long double ans1;
long double ans2;
long double ans3;
if(a1[].pos!=b1[].pos)
ans3=a1[].cha+b1[].cha;
else
{
if(a1[].cha+b1[].cha<a1[].cha+b1[].cha)
ans3=a1[].cha+b1[].cha;
else
ans3=a1[].cha+b1[].cha;
}
ans2=a1[].cha;
ans1=b1[].cha;
cout << setprecision() << setiosflags(ios::scientific)<<sum-max(ans1,max(ans2,ans3))<<endl;
return ;
}
codeforces 352 div 2 C.Recycling Bottles 贪心的更多相关文章
- 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 ...
- Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...
- 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 ...
- Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心
题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...
- Codeforces 671A Recycling Bottles(贪心+思维)
题目链接:http://codeforces.com/problemset/problem/671/A 题目大意:给你两个人的位置和一个箱子的位置,然后给出n个瓶子的位置,要求让至少一个人去捡瓶子放到 ...
- Codeforces Round #352 (Div. 2)
模拟 A - Summer Camp #include <bits/stdc++.h> int a[1100]; int b[100]; int len; void init() { in ...
- Codeforces Round #352 (Div. 2) (A-D)
672A Summer Camp 题意: 1-n数字连成一个字符串, 给定n , 输出字符串的第n个字符.n 很小, 可以直接暴力. Code: #include <bits/stdc++.h& ...
- Codeforces Recycling Bottles 模拟
C. Recycling Bottles time limit per test: 2 seconds memory limit per test: 256 megabytes input: stan ...
- codeforces 672C C. Recycling Bottles(计算几何)
题目链接: C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input s ...
随机推荐
- [py]flask动态展示主机内存图
echarts基础 需要借助这个图来绘制,动态内存图. 绘制步骤 写py脚本来入库日志 选取合适的echart,并观察图所需的数据格式 用flask返回这个静态的echarts 用flask写接口返回 ...
- JavaScript加强
1.Aptana简介 Aptana是一个非常强大,开源,专注于JavaScript的Ajax开发IDE它的特性包括 1.JavaScript,JavaScript函数,HTML,CSS语言的Code ...
- [lr] 常用快捷键
界面基本操作 F5 : 隐藏/显示上部面板 F6 : 隐藏/显示下部面板 F7 : 隐藏/显示左部面板 F8 ...
- excel输入数字变成特殊符号问题
问题,在单元格里输入数字,结果变成文件夹类型的小图片或特殊符号了,原因是字体为Wingdings,将其设为Times New Roman即可
- VS2010中如何实现自定义MFC控件
本文简要讲解在VS2010中怎样实现自定义MFC控件的知识,以下是分步骤说明. 一.自定义一个空白控件 1.先创建一个MFC工程 NEW Project-->MFC-->MFC Appl ...
- uva11419 二分图--最小覆盖=最大匹配
大白书355 // UVa11419 SAM I AM // Rujia Liu #include <cstdio> #include <cstring> #include & ...
- Java线程基础知识(状态、共享与协作)
1.基础概念 CPU核心数和线程数的关系 核心数:线程数=1:1 ;使用了超线程技术后---> 1:2 CPU时间片轮转机制 又称RR调度,会导致上下文切换 什么是进程和线程 进程:程序运行资源 ...
- LoadRunner11支持的浏览器小结-Loadrunner11打不开IE浏览器的问题
http://www.cnblogs.com/qmfsun/p/4807237.html
- linux常用命令:telnet 命令
telnet命令通常用来远程登录.telnet程序是基于TELNET协议的远程登录客户端程序.Telnet协议是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议和主要方式.它为用户 ...
- python 单例模式,一个类只能生成唯一的一个实例,重写__new__方法详解
单例:一个类只能生成唯一的一个实例 每个类只要被实例化了,他的私有属性 '_instance'就会被赋值,这样理解对吗 对 #方法1,实现__new__方法 #并在将一个类的实例绑定到类变量_inst ...