codeforces 672C. Recycling Bottles
来源:互联网 发布:沙丁鱼挂机赚钱软件 编辑:程序博客网 时间:2024/05/22 23:59
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position(xi, yi). Both Adil and Bera can carry only one bottle at once each.
For both Adil and Bera the process looks as follows:
- Choose to stop or to continue to collect bottles.
- If the choice was to continue then choose some bottle and walk towards it.
- Pick this bottle and walk to the recycling bin.
- Go to step 1.
Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles.
They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.
First line of the input contains six integers ax,ay,bx,by,tx andty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.
Then follow n lines, each of them contains two integersxi andyi (0 ≤ xi, yi ≤ 109) — position of the i-th bottle.
It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury isb. The checker program will consider your answer correct if.
3 1 1 2 0 031 12 12 3
11.084259940083
5 0 4 2 2 055 23 05 53 53 3
33.121375178000
Consider the first sample.
Adil will use the following path: .
Bera will use the following path: .
Adil's path will be units long, while Bera's path will be units long.
题意:有两个人和一个垃圾桶, 还有n个瓶子, 现在要人去吧每个瓶子捡起来然后扔到垃圾箱中,求最短的距离,不要去最后人都要回到垃圾箱
思路:假设人都在垃圾箱上,那么总距离为2 * 每个瓶子到箱子的距离,现在人不在上面,所以只要求出
瓶子到箱子的距离 - 人到瓶子的距离的最大值即可再用总和减去这个即可, 注意, 肯定要有一个人先捡瓶子再回垃圾箱的,如果另一个人的最大值小于0,那么久不需要他捡了, 还有注意只有1个瓶子的情况。
(能否ac 取决于你是否细心,诶,比赛时没有考虑全面,1个多小时后被hack了,然后导致D题敲到一半放下去研究C结果,,,你懂得!!)
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <cstdlib>#include <stack>#include <queue>#include <set>#include <map>using namespace std;const int inf = 2147483647;const double PI = acos(-1.0);const double e = 2.718281828459;const int mod = 1000000007;typedef long long LL;#pragma comment(linker, "/STACK:102400000,102400000")//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cinstruct node{double x, y;int id;}a[100005], b[100005];int vis[100005];double xx1, yy1, xx2, yy2, xx, yy;double dis(double x1, double y1, double x2, double y2){return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2) * (y1 - y2));}bool cmp1(node a, node b){return (dis(a.x, a.y, xx, yy) - dis(a.x, a.y, xx1, yy1)) > (dis(b.x, b.y, xx, yy) - dis(b.x, b.y, xx1, yy1));}bool cmp2(node a, node b){return (dis(a.x, a.y, xx, yy) - dis(a.x, a.y, xx2, yy2)) > (dis(b.x, b.y, xx, yy) - dis(b.x, b.y, xx2, yy2));}int main(){int i, j, n;while (cin >> xx1 >> yy1 >> xx2 >> yy2 >> xx >> yy){scanf("%d", &n);memset(vis, 0, sizeof(vis));double s = 0;for (i = 1; i <= n; ++i){scanf("%lf%lf", &a[i].x, &a[i].y);a[i].id = i;b[i].id = i;b[i].x = a[i].x;b[i].y = a[i].y;s += sqrt((a[i].x - xx)*(a[i].x - xx) + (a[i].y - yy) * (a[i].y - yy)) * 2;}double mmax = 0;double a1, b1, a2, b2;sort(a + 1, a + 1 + n, cmp1);vis[a[1].id] = 1;a1 = dis(a[1].x, a[1].y, xx, yy) - dis(a[1].x, a[1].y, xx1, yy1);a2 = dis(a[2].x, a[2].y, xx, yy) - dis(a[2].x, a[2].y, xx1, yy1);sort(b + 1, b + 1 + n, cmp2);b1 = dis(b[1].x, b[1].y, xx, yy) - dis(b[1].x, b[1].y, xx2, yy2);b2 = dis(b[2].x, b[2].y, xx, yy) - dis(b[2].x, b[2].y, xx2, yy2);if (n == 1){mmax = max(a1, b1);}else{if (vis[b[1].id]){mmax = max(max(a1, b2) + max(min(a1, b2), 0.0), max(b1, a2) + max(min(b1, a2), 0.0));//注意要和0比较}elsemmax = max(a1, b1) + max(min(a1, b1), 0.0);}printf("%.12lf\n", s - mmax);}}/*2 1 1 2 0 01 1 1*/
- codeforces 672C. Recycling Bottles
- CodeForces-672C-Recycling Bottles
- codeforces 672C Recycling Bottles
- Codeforces 672C Recycling Bottles (YY)
- codeforces 672C Recycling Bottles (枚举+贪心)
- CodeForces - 672C Recycling Bottles (贪心)
- 【18.69%】【codeforces 672C】Recycling Bottles
- Codeforces 672C Recycling Bottles 几何+贪心
- Codeforces 672 C. Recycling Bottles(Codeforces Round #352 (Div. 2))
- Codeforces 672C Recycling Bottles【极限思维+贪心枚举】
- Codeforces #352 Div2 C Recycling Bottles
- codeforces#352-C - Recycling Bottles-贪心
- Codeforces #352 Recycling Bottles
- Codeforces Round #352 (Div. 2) C. Recycling Bottles
- Codeforces Round #352 (Div. 2) C - Recycling Bottles
- Codeforces Round #352 (Div. 2)C. Recycling Bottles
- Codeforces Round #352 (Div. 2) C. Recycling Bottles
- Codeforces Round #352 (Div. 2) C. Recycling Bottles
- nyoj420 P次方求和(快速幂)
- div table td布局相关属性设置说明
- 聊聊jQuery的反模式
- 用户“Michael-PC\Michael”不具有所需的权限。请验证授予了足够的权限并且解决了 Windows 用户帐户控制(UAC)限制问题。
- libiconv VS2013 x64静态库编译
- codeforces 672C. Recycling Bottles
- 如何在前端项目中实现热更新
- 软件测试方法大汇总
- 微信&java 开发3 菜单接口
- 京东技术架构(二)构建需求响应式亿级商品详情页
- ACM 数论 hdu 1013 Digital Roots
- Linux的命名空间详解--Linux进程的管理与调度(二)
- Ajax 实现级联下拉框
- VS2010安装EntityFramework(图文)