Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心
题目链接:
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 暴力+贪心的更多相关文章
- Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...
- 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 ...
- 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 ...
- 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 ...
- codeforces 352 div 2 C.Recycling Bottles 贪心
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #352 (Div. 2) ABCD
Problems # Name A Summer Camp standard input/output 1 s, 256 MB x3197 B Different is Good ...
- Codeforces Round #352 (Div. 2)
模拟 A - Summer Camp #include <bits/stdc++.h> int a[1100]; int b[100]; int len; void init() { in ...
- Codeforces Round #352 (Div. 2) (A-D)
672A Summer Camp 题意: 1-n数字连成一个字符串, 给定n , 输出字符串的第n个字符.n 很小, 可以直接暴力. Code: #include <bits/stdc++.h& ...
- Codeforces Round #352 (Div. 2) C
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- iOS初学者的AppStore上架应用"菜谱大师"开源了!
本人是一名DoNet程序猿,在业余的时间自学了点iOS,于是就自己弄了一个小菜谱,自己要做菜的时候也就可以用自己的菜谱了. 现在将此应用开源给像我一样对iOS开发有兴趣,并且想学习iOS的园友,毕竟这 ...
- MyEclipse 选中属性或方法后 相同的不变色了?
MyEclipse 选中属性或方法后 相同的不变色了? myeclipse-->windows-->java-->Editor-->Mark Occurrences 把所有的框 ...
- Winform开发常用控件之Checkbox和CheckedListBox
Winform的开发基本都是基于控件事件的,也就是事件驱动型的. 多选框的放置和值的获取有很多种,这里介绍几个简单常用的方法 1.直接放置Checkbox,并获取Checkbox的值 上图 做法也非常 ...
- Hao123这个流氓
Author:KillerLegend Date:2014.2.27 From:http://www.cnblogs.com/killerlegend/p/3572591.html Hao123真让人 ...
- OpenGL 纹理贴图
前一节实例代码中有个贴图操作. 今天就简单说明一下纹理贴图... 为了使用纹理贴图.我们首先需要启用纹理贴图功能. 我们可以在Renderer实现的onSurfaceCreated中定义启用: // ...
- hdu 1874 畅通工程续
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1874 畅通工程续 Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过 ...
- Effective Objective-C 2.0之Note.01
1.在类的头文件中尽量少引入其他头文件 除非确有必要,否则不要引入头文件.一般来说,应在某个类的头文件中使用向前声明来提及别的类,并在实现文件中引入那些类的头文件.这样做可以尽量降低类之间的耦合(co ...
- php捕获网络页面
<?php $url = 'http://jwzx.cqupt.edu.cn/pubYxKebiao.php?type=zy&yx=06'; $html = file_get_conte ...
- R 语言中文乱码问题
R 语言似乎在WINDOWS平台上对中文的支持不是特别好,似乎是3.1.2的一个BUG. 目前我研究出了一个临时解决方案,你可以将代码编写成一个函数,从而在调用的过程中不必如下繁琐: 1. 先将本地语 ...
- 46.谈谈SDRAM的作用
SDRAM这个至今还在用的存储器,虽然被后来的DDR取代,掌握好它还是很重要的.之前在调试时,确实费了好大劲,它的复杂性毋庸置疑,一般人要想弄懂他,得花1个月左右吧,至少我这么认为.话说回来,SDRA ...