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<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c=getchar(); x=0;
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) {x=x*10+c-‘0‘; c=getchar();}
}

const int maxn=100010;
double ax,ay,bx,by,tx,ty;
struct X{ double x,y;int id; }s[maxn];
int n;

bool cmp1(X a,X b)
{
    return sqrt((a.x-ax)*(a.x-ax)+(a.y-ay)*(a.y-ay))-sqrt((a.x-tx)*(a.x-tx)+(a.y-ty)*(a.y-ty))
            <
            sqrt((b.x-ax)*(b.x-ax)+(b.y-ay)*(b.y-ay))-sqrt((b.x-tx)*(b.x-tx)+(b.y-ty)*(b.y-ty));
}

bool cmp2(X a,X b)
{
    return sqrt((a.x-bx)*(a.x-bx)+(a.y-by)*(a.y-by))-sqrt((a.x-tx)*(a.x-tx)+(a.y-ty)*(a.y-ty))
            <
            sqrt((b.x-bx)*(b.x-bx)+(b.y-by)*(b.y-by))-sqrt((b.x-tx)*(b.x-tx)+(b.y-ty)*(b.y-ty));
}

bool cmp3(X a,X b)
{
    return a.id<b.id;
}

int a[maxn],sz;

int main()
{
    scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty);

    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lf%lf",&s[i].x,&s[i].y),s[i].id=i;

    if(n==1)
    {
        double ans;
        ans=min(sqrt((ax-s[1].x)*(ax-s[1].x)+(ay-s[1].y)*(ay-s[1].y))+
                sqrt((tx-s[1].x)*(tx-s[1].x)+(ty-s[1].y)*(ty-s[1].y))
                ,
                sqrt((bx-s[1].x)*(bx-s[1].x)+(by-s[1].y)*(by-s[1].y))+
                sqrt((tx-s[1].x)*(tx-s[1].x)+(ty-s[1].y)*(ty-s[1].y))
                );
        printf("%.6lf\n",ans);
        return 0;
    }

    double ans=999999999999999999;
    double g=0;
    for(int i=1;i<=n;i++) g=g+2*sqrt((s[i].x-tx)*(s[i].x-tx)+(s[i].y-ty)*(s[i].y-ty));

    sort(s+1,s+1+n,cmp1);
    ans=min(ans,
            g+sqrt((s[1].x-ax)*(s[1].x-ax)+(s[1].y-ay)*(s[1].y-ay))
            -sqrt((s[1].x-tx)*(s[1].x-tx)+(s[1].y-ty)*(s[1].y-ty)));
    for(int i=1;i<=min(n,2);i++) a[sz++]=s[i].id;

    sort(s+1,s+1+n,cmp2);
    ans=min(ans,
            g+sqrt((s[1].x-bx)*(s[1].x-bx)+(s[1].y-by)*(s[1].y-by))
            -sqrt((s[1].x-tx)*(s[1].x-tx)+(s[1].y-ty)*(s[1].y-ty)));
    for(int i=1;i<=min(n,2);i++) a[sz++]=s[i].id;

    sort(s+1,s+1+n,cmp3);

    for(int i=0; i<sz; i++)
    {
        for(int j=0; j<sz; j++)
        {
            if(a[j]==a[i]) continue;

            double tmp=g;
            tmp=tmp+sqrt((s[a[i]].x-ax)*(s[a[i]].x-ax)+(s[a[i]].y-ay)*(s[a[i]].y-ay));
            tmp=tmp+sqrt((s[a[j]].x-bx)*(s[a[j]].x-bx)+(s[a[j]].y-by)*(s[a[j]].y-by));
            tmp=tmp-sqrt((s[a[i]].x-tx)*(s[a[i]].x-tx)+(s[a[i]].y-ty)*(s[a[i]].y-ty));
            tmp=tmp-sqrt((s[a[j]].x-tx)*(s[a[j]].x-tx)+(s[a[j]].y-ty)*(s[a[j]].y-ty));

            ans=min(ans,tmp);
        }
    }
    printf("%.6lf\n",ans);
    return 0;
}
时间: 2024-10-29 19:10:40

CodeForces 671A Recycling Bottles的相关文章

【模拟】Codeforces 671A Recycling Bottles

题目链接: http://codeforces.com/problemset/problem/671/A 题目大意: A和B在一张二维平面上,平面上有N个垃圾,垃圾桶只有一个在T,问把所有垃圾全扔进垃圾桶最少走多远.一次只能拿一个垃圾.允许一个人走另一个人停下来. (1 ≤ n ≤ 100 000)  (0 ≤ xi, yi ≤ 109) 题目思路: [模拟] 因为每次只能携带一个垃圾,大部分垃圾都是人扔完上一个垃圾后,从垃圾桶出发去捡的. 而最多有两个垃圾不是被人从垃圾桶出发完再扔到垃圾桶.

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

Codeforces Round #352 (Div. 2) ABCD

Problems # Name     A Summer Camp standard input/output 1 s, 256 MB    x3197 B Different is Good standard input/output 2 s, 256 MB    x2870 C Recycling Bottles standard input/output 2 s, 256 MB    x664 D Robin Hood standard input/output 1 s, 256 MB  

Bottles CodeForces - 730J

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 bottles, moreover he has to do