• 【模拟】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
    ",anss-z);
    100     }
    101     return 0;
    102 }
    103 /*
    104 //
    105 
    106 //
    107 */
    View Code
  • 相关阅读:
    【STM32H7】第3章 ThreadX GUIX和GUIX Studio介绍
    【STM32F429】第3章 ThreadX GUIX和GUIX Studio介绍
    Spring Boot Devtools 依赖详解
    《深入理解 Java 虚拟机》-- 读书笔记
    JAVA连接MySQ报错:Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version
    JAVA生成文件的md5校验值
    IDEA启动报错:Error:java: Compilation failed: internal java compiler error
    JAVA读取本地html文件里的html文本
    SpringBoot打包实现静态文件、配置文件、jar包分离
    SpringBoot中Post请求提交富文本数据量过大参数无法获取的问题
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5785014.html
Copyright © 2020-2023  润新知