题目链接:

http://codeforces.com/contest/672/problem/C

题意:

公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶,瓶子的坐标,问两个人需要走的最短距离和。

题解:

首先必须要有一个人先去检一个瓶子,然后走到垃圾桶,这个可以枚举,接下来就是考虑另一个人是也捡一个瓶子然后走到垃圾桶(这个可以预处理出最优的,和次优的,因为如果最优的那个刚好被第一个人拿走了,那就拿次优的)还是在原地不动,接下去就是固定的了,求剩下的所有瓶子到垃圾桶的距离的两倍就可以了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; const int maxn = 1e5+;
const double eps = 1e-;
typedef long long LL; struct Point {
int x, y;
Point(int x, int y) :x(x), y(y) {}
Point() {}
}pt[maxn]; inline double dis(const Point& n1, const Point& n2) {
return sqrt((LL)(n1.x - n2.x)*(n1.x - n2.x) + (LL)(n1.y-n2.y)*(n1.y - n2.y));
} int ax, ay, bx, by, tx, ty,n;
double cnt; struct Node {
int id;
double v;
bool operator < (const Node& tmp)const {
return v< tmp.v;
}
}nda[maxn],ndb[maxn];
void pre(Point aa, Point bb, const Point &bin) {
for (int i = ; i < n; i++){
nda[i].v = dis(aa, pt[i]) - dis(bin, pt[i]); nda[i].id = i;
ndb[i].v = dis(bb, pt[i]) - dis(bin, pt[i]); ndb[i].id = i;
}
sort(nda, nda + n);
sort(ndb, ndb + n); } double solve(const Node* nd,Point aa, Point bb, const Point &bin) {
//这个地方写成了ret=cnt,哇在41哇了好几个小时!!!!!!!!!!!!!!!
//这样如果两个人都不动会更优的话就变成输出两个人都不动的答案啦!人都没动,垃圾桶不会自己去找瓶子啊!!!!
//orz orz orz
double ret;
for (int i = ; i < n; i++) {
double sum = cnt - dis(bin, pt[i])+dis(aa,pt[i]);
if (nd[].id != i) {
sum = min(sum,sum + nd[].v);
}
else {
if(n>) sum = min(sum,sum + nd[].v);
}
if (i == ) ret = sum;
else ret = min(ret, sum);
}
return ret;
} void init() {
cnt = ;
} int main() {
while (scanf("%d%d%d%d%d%d", &ax, &ay, &bx, &by, &tx, &ty) == ) {
init();
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%d%d", &pt[i].x, &pt[i].y);
cnt += dis(pt[i], Point(tx, ty))*;
}
pre(Point(ax, ay), Point(bx, by), Point(tx, ty));
double ans;
ans=solve(ndb,Point(ax, ay), Point(bx, by), Point(tx, ty));
ans=min(ans,solve(nda,Point(bx, by),Point(ax, ay), Point(tx, ty)));
printf("%.12lf\n", ans);
}
return ;
} /*
1 0 0 1 0 0
2
1 1
2 2
*/

Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心的更多相关文章

  1. Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力

    A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心

    Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  5. codeforces 352 div 2 C.Recycling Bottles 贪心

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. Codeforces Round #352 (Div. 2) ABCD

    Problems     # Name     A Summer Camp standard input/output 1 s, 256 MB    x3197 B Different is Good ...

  7. Codeforces Round #352 (Div. 2)

    模拟 A - Summer Camp #include <bits/stdc++.h> int a[1100]; int b[100]; int len; void init() { in ...

  8. Codeforces Round #352 (Div. 2) (A-D)

    672A Summer Camp 题意: 1-n数字连成一个字符串, 给定n , 输出字符串的第n个字符.n 很小, 可以直接暴力. Code: #include <bits/stdc++.h& ...

  9. Codeforces Round #352 (Div. 2) C

    C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. 为什么for in循环不适合用于数组

    首先一点无关的,使用(var i in a) 而不是( i in a),除非你想创建全局变量. 第二点,for in 循环会忽略空的数组 var a = []; a[5] = 5; // Perfec ...

  2. POJ C程序设计进阶 编程题#4:括号匹配问题

    编程题#4:扩号匹配问题 来源: POJ(Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 在某 ...

  3. SQLServer中用户 'sa' 登录失败解决办法

    今天下午,很奇怪的网站突然就打不开了,报错如下: “/”应用程序中的服务器错误. 用户 'sa' 登录失败. 说明: 执行当前 Web 请求期间,出现未处理的异常.请检查堆栈跟踪信息,以了解有关该错误 ...

  4. mybatis动态sql中的trim标签的使用(转)

    trim标记是一个格式化的标记,可以完成set或者是where标记的功能,如下代码: 1. select * from user <trim prefix="WHERE" p ...

  5. C++12!配对

    题目内容:找出输入数据中所有两两相乘的积为12!的对数. 输入描述:输入数据中含有一些整数n(1<=n<232). 输出描述:输出所有两两相乘的积为12!的对数. 题目分析:对于输入的每个 ...

  6. 删:Centos 7安装Nginx 1.8

    [CentOS 7] 安装nginx! 首先进行 nginx yum Nginx安装记录 注意:如果用源码安装,nginx配置时需要指定--with-pcer对应的压缩包路径,如果使用二进制安装不需要 ...

  7. 删:[CentOS 7] 安装nginx

    下载对应当前系统版本的nginx包(package) # wget  http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-cent ...

  8. DOS下更改编码方式

    使用CHCP命令,CHCP是Change Code Page的缩写. 936 简体中文GBK 437 美国英语 65001 UTF编码 如:chcp 65001则将dos窗口中的字符编码改为UTF编码 ...

  9. delphi android 中 Toast 的实现(老外写的UNIT)

    unit Android.JNI.Toast; // Java bridge class imported by hand by Brian Long (http://blong.com)interf ...

  10. 访问svc 文件,编译器错误消息: CS0016,未能写入输出文件

    编译错误              说明: 在编译向该请求提供服务所需资源的过程中出现错误.请检查下列特定错误详细信息并适当地修改源代码.             编译器错误消息: CS0016: 未 ...