CF 672C 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.
稍微一想,除了开始后面都是从bin来回
只要找从a b到某个瓶子比从bin到节省最多就可以了
特殊情况太多:
有人是负值 不走他
最优瓶子一样 找次优
次优中还有负值
调了一个多小时,WA无数
//
// main.cpp
// cf672c
//
// Created by Candy on 9/15/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const double INF=1e10;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x;
}
int xa,ya,xb,yb,xt,yt,x,y;
int n,bot[];
double mx[],sum=;//1 2->a 3 4->b
double dist(ll a,ll b){
return sqrt(a*a+b*b);
}
double getans(double a,double b){
if(a<||b<){//printf("flag2\n");
if(a<b) a=;
else b=;
}
return a+b;
}
int main(int argc, const char * argv[]) {
mx[]=mx[]=mx[]=mx[]=-INF;
scanf("%d%d%d%d%d%d%d",&xa,&ya,&xb,&yb,&xt,&yt,&n);//cout<<"\na"<<xa<<" "<<ya<<"\n";
for(int i=;i<=n;i++){
x=read();y=read();
double to=dist(x-xt,y-yt); sum+=to*;//printf("to %d %d %lf\n",x-xt,y-yt,to);
double t1=to-dist(x-xa,y-ya),t2=to-dist(x-xb,y-yb);
if(t1>mx[]){
mx[]=mx[]; bot[]=bot[];
mx[]=t1; bot[]=i;
}else if(t1>mx[]){
mx[]=t1; bot[]=i;
}
if(t2>mx[]){
mx[]=mx[]; bot[]=bot[];
mx[]=t2; bot[]=i;
}else if(t2>mx[]){
mx[]=t2; bot[]=i;
}
} //if(n==1) {printf("%.12f",sum-max(mx[1],mx[3]));return 0;}
//printf("%lf %d %lf %d\n",mx[1],bot[1],mx[3],bot[3]);
if(mx[]<||mx[]<){//printf("flag2\n");
if(mx[]<mx[]) mx[]=,bot[]=;
else mx[]=,bot[]=;
}
if(bot[]==bot[]){//printf("flag1 %lf %lf\n",mx[2],mx[4]);
if(getans(mx[],mx[])>getans(mx[],mx[])){
mx[]=mx[];//cout<<mx[1]<<" mx1\n";
}else{
mx[]=mx[];//,cout<<mx[3]<<" mx3\n";
}
if(mx[]<||mx[]<){//printf("flag2\n");
if(mx[]<mx[]) mx[]=,bot[]=;
else mx[]=,bot[]=;
}
}
printf("%.12f",sum-mx[]-mx[]);
return ;
}
CF 672C Recycling Bottles[最优次优 贪心]的更多相关文章
- codeforces 672C - Recycling Bottles 贪心水题
感觉很简单,就是讨论一下 #include <stdio.h> #include <string.h> #include <algorithm> #include ...
- codeforces 672C C. Recycling Bottles(计算几何)
题目链接: C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- 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 352 div 2 C.Recycling Bottles 贪心
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CF 672C 两个人捡瓶子 最短路与次短路思想
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- Codeforces Recycling Bottles 模拟
C. Recycling Bottles time limit per test: 2 seconds memory limit per test: 256 megabytes input: stan ...
- Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...
- Codeforces 671 A——Recycling Bottles——————【思维题】
Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 系统安装LOL等游戏后出现VS调试报错"无法调试""拒绝访问"之类的调试错误
一个问题抠得脑壳痛,度娘一番各种各样的答案.基本属于 1,调试权限被清0 2,文件权限问题 其中看到很多解决方案中提到"重启电脑"的说法.我也试了几次不行甚至游戏都卸载了.后来 ...
- vbs操作excel
航天金税系统升级,导出的Excel文件格式与原来有的差异,老的数据导入程序识别不了该文件,对比了新老文件后,发现新文件在专票和普票的“份数”行前增加了一行,同时增加了“单据号”列,通过脚本 把这些删除 ...
- SharePoint2007:解决第二回收站大数据无法删除问题
Emptying the Second Stage Recycle Bin in SharePoint 2007 Look in your second stage recycle bin in ...
- Android studio git 本地仓库和远程仓库节点对比
1.初始状态 2.本地修改文件,然后commit 3.本地再次修改文件,然后commit 4.本地push 从上图可以看出,push完成后,本地仓库的节点和远程仓库的节点是一样的.
- 【iOS】彩色TabBar切换动画实现
无意间看到一个彩色TabBar切换的设计图,感觉很不错,有空就把他实现了. 环境信息 Mac OS X 10.10.4 Xcode 6.4 iOS 8.4 效果图: 效果图 源码下载地址: https ...
- svn(http)
对于有些公司的运维 他确实很垃圾 所以 你一定要谨记这一点!!!
- Android touch事件处理流程
前面我们看了key事件的处理流程,相信大家对此已经有了新的认识,这篇文章我打算带领大家来看看稍微复杂些的touch 事件的处理流程.说它复杂是因为key事件本身就key down,up,long pr ...
- 试用 Nexus OSS 3.0 的docker仓库 (一)
Nexus 3.0 可以创建三种docker仓库: 1. docker (proxy) 代理和缓存远程仓库 ,只能pull 2. docker (hosted) 托管仓库 ,私有仓库, ...
- 【译】Java中的对象序列化
前言 好久没翻译simple java了,睡前来一篇. 译文链接: http://www.programcreek.com/2014/01/java-serialization/ 什么是对象序列化 在 ...
- input 默认值为灰色,输入时清楚默认值
input 默认值为灰色,输入时清楚默认值 <input value="please input your name" onFocus="if(value==def ...