【模拟】Codeforces 671A Recycling Bottles

题目链接:

  http://codeforces.com/problemset/problem/671/A

题目大意:

  A和B在一张二维平面上,平面上有N个垃圾,垃圾桶只有一个在T,问把所有垃圾全扔进垃圾桶最少走多远。一次只能拿一个垃圾。允许一个人走另一个人停下来。

  (1 ≤ n ≤ 100 000)  (0 ≤ xi, yi ≤ 109)

题目思路:

  【模拟】

  因为每次只能携带一个垃圾,大部分垃圾都是人扔完上一个垃圾后,从垃圾桶出发去捡的。

  而最多有两个垃圾不是被人从垃圾桶出发完再扔到垃圾桶。

  可以先将答案算作都从垃圾桶开始往返捡的距离,再枚举哪一个垃圾被人直接走过去捡能优化答案。注意不要让两个人都选择同一个垃圾。

  1 //
  2 //by coolxxx
  3 //#include<bits/stdc++.h>
  4 #include<iostream>
  5 #include<algorithm>
  6 #include<string>
  7 #include<iomanip>
  8 #include<map>
  9 #include<memory.h>
 10 #include<time.h>
 11 #include<stdio.h>
 12 #include<stdlib.h>
 13 #include<string.h>
 14 //#include<stdbool.h>
 15 #include<math.h>
 16 #define min(a,b) ((a)<(b)?(a):(b))
 17 #define max(a,b) ((a)>(b)?(a):(b))
 18 #define abs(a) ((a)>0?(a):(-(a)))
 19 #define lowbit(a) (a&(-a))
 20 #define sqr(a) ((a)*(a))
 21 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
 22 #define mem(a,b) memset(a,b,sizeof(a))
 23 #define eps (1e-8)
 24 #define J 10
 25 #define mod 1000000007
 26 #define MAX 0x7f7f7f7f
 27 #define PI 3.14159265358979323
 28 #define N 100004
 29 using namespace std;
 30 typedef long long LL;
 31 int cas,cass;
 32 int n,m,lll,ans;
 33 double anss;
 34 struct xxx
 35 {
 36     LL x,y;
 37     double disa,disb,dist;
 38 }q[N],a,b,t;
 39 double dis(xxx aa,xxx bb)
 40 {
 41     return sqrt(sqr(aa.x-bb.x)+sqr(aa.y-bb.y));
 42 }
 43 bool cmp(xxx aa,xxx bb)
 44 {
 45     return aa.dist<bb.dist;
 46 }
 47 int main()
 48 {
 49     #ifndef ONLINE_JUDGE
 50     freopen("1.txt","r",stdin);
 51 //    freopen("2.txt","w",stdout);
 52     #endif
 53     int i,j,ma,mb;
 54     double ax,ay,bx,by,z;
 55 //    for(scanf("%d",&cas);cas;cas--)
 56 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
 57     while(~scanf("%I64d",&a.x))
 58 //    while(~scanf("%d",&n))
 59     {
 60         anss=0;ay=by=0;
 61         scanf("%I64d%I64d%I64d%I64d%I64d",&a.y,&b.x,&b.y,&t.x,&t.y);
 62         scanf("%d",&n);
 63         for(i=1;i<=n;i++)
 64         {
 65             scanf("%I64d%I64d",&q[i].x,&q[i].y);
 66             q[i].disa=dis(a,q[i]);
 67             q[i].disb=dis(b,q[i]);
 68             q[i].dist=dis(t,q[i]);
 69         }
 70         sort(q+1,q+1+n,cmp);
 71         anss=q[1].dist+q[1].dist;
 72         ax=q[1].dist-q[1].disa;
 73         bx=q[1].dist-q[1].disb;
 74         ma=mb=1;
 75         for(i=2;i<=n;i++)
 76         {
 77             anss+=q[i].dist+q[i].dist;
 78             z=q[i].dist-q[i].disa;
 79             if(ax<z)
 80             {
 81                 ay=max(ax,ay);
 82                 ax=z;
 83                 ma=i;
 84             }
 85             else ay=max(ay,z);
 86             z=q[i].dist-q[i].disb;
 87             if(bx<z)
 88             {
 89                 by=max(bx,by);
 90                 bx=z;
 91                 mb=i;
 92             }
 93             else by=max(by,z);
 94         }
 95         if(ma!=mb)z=ax+bx;
 96         else z=max(ax+by,bx+ay);
 97         z=max(z,ax);
 98         z=max(z,bx);
 99         printf("%.12lf\n",anss-z);
100     }
101     return 0;
102 }
103 /*
104 //
105
106 //
107 */

时间: 2024-08-11 17:33:51

【模拟】Codeforces 671A Recycling Bottles的相关文章

CodeForces 671A Recycling Bottles

#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include&

codeforces 672C - Recycling Bottles 贪心水题

感觉很简单,就是讨论一下 #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; typedef pair<double,int>pii; const int N = 1e5+5; double x[N],y[N]; pii a[N],b[N]; double dis(double x1,double y1

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 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 bottle

Codeforces Round #352 (Div. 2) C. Recycling Bottles(枚举)

思路:分析完这道题后会发现  当两个人捡到第一个瓶子后, 之后走的路的最小值都是不会变的了. 所以只要找出两个走到各自的第一个瓶子是最小值的情况的时候(其中还有一个人不走,一个人走的情况).   如果当有两个人或有一个人到其第一个瓶子的权值大于瓶子到回收点时,选取权值小的那个. 而且计算最小值的时候 只需取出两个权值数组中最小的两个数 即可 不用全部遍历来选取. #include<iostream> #include<cstdio> #include<cmath> #i

模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

题目传送门 1 /* 2 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 3 题目倒是很长:) 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <algorithm> 9 #include <cstring> 10 using namespace std; 11 12 const int MAXN = 2e5 + 10; 13

queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

题目传送门 1 /* 2 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 3 queue容器:模拟上述过程,当次数达到最大值时判断为-1 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cstring> 9 #include <string> 10 #include <stack> 11 #in

【CodeForces】 730J Bottles

传送门 codeforces luogu 题目描述 Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai?≤?bi). Nick has decided to pour all remaining soda into minimal number of bottl

codeforces 730 J Bottles

题目链接:https://codeforces.com/contest/730/problem/J 题意: 给你 n 瓶水,每瓶水量 ai,容量 bi.要将所有水装到尽量少的瓶子内. 每移动一单位的水要消耗一单位时间,在最少瓶子的前提下,问移动水所需的最短时间. 分析: dp 建立个三维dp[i][j][k] ( 这题刚好可以卡个 1e8 的空间 ① dp[i][j][k] 表示前 i 个瓶子 , 挑选了 j 个 , 瓶子总容量为 k 时 , 所有瓶子里最大的水量和 ② dp[i][j][k]

codeforces 的20道C题

A - Warrior and Archer CodeForces - 595C n  偶数  然后n个数字 A B 轮流取一个 A让差变小B让差变大 直到最后2 个   求的是最小剩下的差 最后剩下的 L R  相距 n/2    求一下最小的就行 #include <iostream> #include <cstdio> #include <cmath> #include <map> #include <algorithm> #include