题目链接:

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. jQuery bind and unbind (绑定和解除)

    测试:页面代码: <body> <input type="button" name="aaa" value="点击我"&g ...

  2. shell 截取指定的字符串

    按指定的字符串截取 1.第一种方法: ${varible##*string} 从左向右截取最后一个string后的字符串 ${varible#*string}从左向右截取第一个string后的字符串 ...

  3. c#中判断对象为空的几种方式(字符串等)

    (1)先了解几个与空类型相关的关键字和对象  Null : 关键字表示不引用任何对象的空引用,它是所有引用类型变量的默认值,在2.0版本之前也就只有引用变量类型可以为null,如(string a=n ...

  4. Fragment的创建以及与activity的参数传递

    点击下面不同的TextView变化不同的Fragment avtivity与Fragment之间传递消息不能使用构造器传递,用bunder传递 首先写一个含有FrameLayout(这个布局最佳),里 ...

  5. 【easyui】--普通js中获取easyui中分页信息(page,pageSize等)

    对于datagrid,获取其分页信息: 方法: var pageopt = $('#list_data').datagrid('getPager').data("pagination&quo ...

  6. delphi 基础之四 delphi 组织结构

    delphi 组织结构 在Delphi中,一个正在开发的应用程序可以被称作项目或者工程.一般地,一个项目主要由dpr(项目).pas(单元)和dfm(窗体)三种文件组成,另外还有一些附属文件,如res ...

  7. 信驰达携“Zigbee Light Link灯控方案”亮相第18届广州国际照明展

    2013年6月9日至12日,第18届广州国际照明展览会在琶洲中国进出口商品交易会展馆举行,作为全球照明及LED行业风向标和晴雨表,本次展会吸引了来自27个国际及地区,共2600多家企业参展.我公司受T ...

  8. 记一个python+sqlalchemy+tornado的一个高并发下,产生重复记录的bug

    场景:在用户通过支付通道支付完成返回时,发现我收到的处理数据记录中有两条同样的数据记录, 也就是同一笔钱,我数据库中记为了两条一样的记录. tornado端代码 from tornado import ...

  9. MySQL 的数值数据类型

    MySQL 的数值数据类型可以大致划分为两个类别,一个是整数,另一个是浮点数或小数.许多不同的子类型对这些类别中的每一个都是可用的,每个子类型支持不同大小的数据,并且 MySQL 允许我们指定数值字段 ...

  10. poj 3061 Subsequence

    题目连接 http://poj.org/problem?id=3061 Subsequence Description A sequence of N positive integers (10 &l ...