题目链接:

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. 使用Visual Studio Code开发Asp.Net Core WebApi学习笔记(七)-- 结构化配置

    本篇将记录.Net Core里颇有特色的结构化配置的使用方法. 相比较之前通过Web.Config或者App.Config配置文件里使用xml节点定义配置内容的方式,.Net Core在配置系统上发生 ...

  2. Cassandra 计数器counter类型和它的限制

    文档基础 Cassandra 2.* CQL3.1 翻译多数来自这个文档 更新于2015年9月7日,最后有参考资料 作为Cassandra的一种类型之一,Counter类型算是限制最多的一个.Coun ...

  3. CodeBlocks背景主题的设置

    来自:http://blog.csdn.net/gzshun/article/details/8294305 找了好几个CodeBlocks的背景色,都不太如人意.感觉下面这个还不错,所以转来给大家分 ...

  4. Laravel 5 基础(十二)- 认证

    Laravel 出厂已经带有了用户认证系统,我们来看一下 routes.php,如果删除了,添加上: Route::controllers([ 'auth' => 'Auth\AuthContr ...

  5. 使用WIF实现单点登录Part I——Windows Identity Foundation介绍及环境搭建

    首先先说一下什么是WIF(Windows Identity Foundation).由于各种历史原因,身份验证和标识的管理一般都比较无规律可循.在软件里加入“身份验证”功能意味着要在你的代码里混进处理 ...

  6. 《大话设计模式》ruby版代码:策略模式

    需求: 商场收银软件,根据客户购买物品的单价和数量,计算费用,会有促销活动,打八折,满三百减一百之类的. 一,使用工厂模式. # -*- encoding: utf-8 -*- #现金收费抽象类 cl ...

  7. Flask —— 使用Python和OpenShift进行即时Web开发

    最近Packtpub找到了我,让我给他们新出版的关于Flask的书写书评.Flask是一个很流行的Python框架.那本书是Ron DuPlain写的<Flask 即时Web开发>.我决定 ...

  8. oracle 修改表空间存储路径

    [root@yoon ~]# more /etc/oracle-releaseOracle Linux Server release 5.7 Oracle Database 11g Enterpris ...

  9. Android HTTP session && cookie

    HTTP协议与状态保持HTTP协议本身是无状态的,这与HTTP协议本来的目的是相符的,客户端只需要简单的向服务器请求下载某些文件,无论是客户端还是服务器都没有必要纪录彼此过去的行为,每一次请求之间都是 ...

  10. OpenStack:安装Keystone

    >安装Keystone1. 安装# apt-get install keystone2. 创建dbcreate database keystone;grant all privileges on ...