题目链接:

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. C#获取本周周一的日期

    /// <summary> /// 获取本周的周一日期 /// </summary> /// <returns></returns> public st ...

  2. C#访问配置文件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  3. VS2010在非IE浏览器下调试Silverlight程序

    以Chrome为例: 第一步:在程序中设置断点. 第二步:右键点击web应用程序的起始页(.html或.aspx文件),选择"浏览方式",选中Chrome或其它非IE浏览器,点&q ...

  4. XP极限编程

    13个核心实战  团队协作(Whole Team)  规划策略(The Planning Game) 软件发布计划(ReleasePlanning) 周期开发计划(IterationPlanning) ...

  5. POI中设置Excel单元格格式样式(居中,字体,边框等)

    创建sheet什么的就不多说了,直接进入正题 HSSFCellStyle cellStyle = wb.createCellStyle();   一.设置背景色: cellStyle.setFillF ...

  6. 第七节:使用实现了dispose模式的类型

    知道类型如何实现dispose模式之后,接下来看一下开发人员怎样使用提供了dispose模式的类型.这里不再讨论前面的SafeHandle类,而是讨论更常用的FileStream类. 可以利用File ...

  7. Python开发【第一篇】Python基础之字符串格式化

    字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-310 ...

  8. C# 自定义集合

    自定义类型 public class Product { public int Id { get; set; } // 自增ID public string Name { get; set; } // ...

  9. 菜鸟学习Spring——初识Spring

    一.概念. Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Develop ...

  10. Oracle数据迁移至MySQL

    ORACLE DB: 11.2.0.3.0 MYSQL DB: 5.5.14 因项目需求,需要将ORACLE生产中数据迁移至MYSQL数据库中作为初始数据,方法有如下几种: 1.ORACLE OGG ...