codeforces 672C - Recycling Bottles 贪心水题
感觉很简单,就是讨论一下
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef pair<double,int>pii;
const int N = 1e5+;
double x[N],y[N];
pii a[N],b[N];
double dis(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
double ax,ay,bx,by,tx,ty,sum=;
int n;
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",&x[i],&y[i]);
for(int i=;i<=n;++i){
a[i].second=b[i].second=i;
double k1=dis(ax,ay,x[i],y[i]);
double k2=dis(bx,by,x[i],y[i]);
double k3=dis(tx,ty,x[i],y[i]);
sum+=k3*;
a[i].first=k1-k3;
b[i].first=k2-k3;
}
sort(a+,a++n);
sort(b+,b++n);
if(a[].first>=&&b[].first>=){
sum+=min(a[].first,b[].first);
}
else if(a[].first<&&b[].first>=){
sum+=a[].first;
}
else if(a[].first>=&&b[].first<){
sum+=b[].first;
}
else {
if(a[].second!=b[].second){
sum+=a[].first+b[].first;
}
else {
if(n==)sum+=min(a[].first,b[].first);
else {
double k1=a[].first+b[].first;
double k2=b[].first+a[].first;
k1=min(min(k1,k2),min(a[].first,b[].first));
sum+=k1;
}
}
}
printf("%.8f\n",sum);
return ;
}
codeforces 672C - Recycling Bottles 贪心水题的更多相关文章
- PAT甲题题解-1125. Chain the Ropes (25)-贪心水题
贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...
- Codeforces 671 A——Recycling Bottles——————【思维题】
Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF 672C Recycling Bottles[最优次优 贪心]
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #493 (Div. 2) A. Balloons 贪心水题
由于是输出任意一组解,可以将价值从小到大进行排序,第一个人只选第一个,第二个人选其余的.再比较一下第一个人选的元素和第二个人所选元素和是否相等即可.由于已将所有元素价值从小到大排过序,这样可以保证在有 ...
- 【模拟】Codeforces 671A Recycling Bottles
题目链接: http://codeforces.com/problemset/problem/671/A 题目大意: A和B在一张二维平面上,平面上有N个垃圾,垃圾桶只有一个在T,问把所有垃圾全扔进垃 ...
- Codeforces 671A Recycling Bottles(贪心+思维)
题目链接:http://codeforces.com/problemset/problem/671/A 题目大意:给你两个人的位置和一个箱子的位置,然后给出n个瓶子的位置,要求让至少一个人去捡瓶子放到 ...
- 【贪心算法】POJ-2393 简单贪心水题
一.题目 Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over ...
- UVA 11389 The Bus Driver Problem 贪心水题
题目链接:UVA - 11389 题意描述:有n个司机,n个早班路线和n个晚班路线,给每个司机安排一个早班路线和一个晚班路线,使得每个早班路线和晚班路线只属于一个司机.如果一个司机早班和晚班总的驾驶时 ...
- cogs 1440. [NOIP2013]积木大赛 贪心水题
1440. [NOIP2013]积木大赛 ★★ 输入文件:BlockNOIP2013.in 输出文件:BlockNOIP2013.out 简单对比时间限制:1 s 内存限制:128 M ...
随机推荐
- speed up your sharepoint
1. warm up http://blog.nowan.hu/post/SPWakeUp-Wake-up-your-SharePoint-quickly http://blogs.msdn.com/ ...
- MBProgressHUD ---
1,MBProgressHUD常用属性和用法Demo - (void)testMBProgressHUD { NSLog(@"test MBProgressHUD "); /* 要 ...
- bnu 4351 美女来找茬(水水)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4351 [题意]:用最小的矩形框,框住像素点差超过5的点. [题解]:求坐标x,y最大最小值 [cod ...
- dtGrid插件集成到Angular环境实现表格化数据展现
00没有抱怨的世界 周末效率好低,两天没更了,看看这看看那,装了个win10发现触摸板驱动不适配,然后找了好久都不行,23333. AngularJS用的时间很短,高级的用法有点吃不消了,$diges ...
- 1187: [HNOI2007]神奇游乐园 - BZOJ
Description 经历了一段艰辛的旅程后,主人公小P乘坐飞艇返回.在返回的途中,小P发现在漫无边际的沙漠中,有一块狭长的绿地特别显眼.往下仔细一看,才发现这是一个游乐场,专为旅途中疲惫的人设计. ...
- mac忘记密码的解决办法
开机, 启动时按"cmd+S".这时,你会进入Single User Model,出现像DOS一样的提示符 #root>.请在#root>下 输入 (注意空格, 大小写 ...
- scikit-learn安装
1.依赖包: Cython.rose.numpy.scipy.lapack.atlas http://blog.chinaunix.net/uid-22488454-id-3978860.html
- Python 异常结构
http://flyheaven.blog.163.com/blog/static/7401172201193085243920/ 1.Python内建异常体系结构 The class hierarc ...
- 学习笔记:shared_ptr陷阱
条款1:不要把一个原生指针给多个shared_ptr管理 int* ptr = new int; shared_ptr<int> p1(ptr); shared_ptr<int> ...
- linux 使用kill命令杀死进程的几个办法
常规篇: 首先,用ps查看进程,方法如下: $ ps -ef ……smx 1822 1 0 11:38 ? 00:00:49 gnome-terminalsmx ...