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,double x2,double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
    double ax,ay,bx,by,tx,ty,sum=0;
    int n;
    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",&x[i],&y[i]);
    for(int i=1;i<=n;++i){
      a[i].second=b[i].second=i;
      double k1=dis(ax,ay,x[i],y[i]);
      double k2=dis(bx,by,x[i],y[i]);
      double k3=dis(tx,ty,x[i],y[i]);
      sum+=k3*2;
      a[i].first=k1-k3;
      b[i].first=k2-k3;
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    if(a[1].first>=0&&b[1].first>=0){
        sum+=min(a[1].first,b[1].first);
    }
    else if(a[1].first<0&&b[1].first>=0){
        sum+=a[1].first;
    }
    else if(a[1].first>=0&&b[1].first<0){
        sum+=b[1].first;
    }
    else {
       if(a[1].second!=b[1].second){
        sum+=a[1].first+b[1].first;
       }
       else {
         if(n==1)sum+=min(a[1].first,b[1].first);
         else {
            double k1=a[1].first+b[2].first;
            double k2=b[1].first+a[2].first;
            k1=min(min(k1,k2),min(a[1].first,b[1].first));
            sum+=k1;
         }
       }
    }
    printf("%.8f\n",sum);
    return 0;
}

时间: 2024-10-17 15:07:09

codeforces 672C - Recycling Bottles 贪心水题的相关文章

UVA 11389 The Bus Driver Problem 贪心水题

题目链接:UVA - 11389 题意描述:有n个司机,n个早班路线和n个晚班路线,给每个司机安排一个早班路线和一个晚班路线,使得每个早班路线和晚班路线只属于一个司机.如果一个司机早班和晚班总的驾驶时间超过d,那么超出的时间按每小时r元付给司机.求最小的费用. 算法分析:一枚贪心的小水题.对早班路线的时间按照从大到小排序,对晚班路线的时间按照从小到大排序,然后就可以了. 1 #include<iostream> 2 #include<cstdio> 3 #include<cs

【模拟】Codeforces 671A Recycling Bottles

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

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&

hdu_2124 Flying to the Mars &amp; hdu_1800 Repair the Wall 贪心水题

hdu_1800 简单排一下序,从大开始把比他小的都访问一遍,ans++: #include <iostream> #include <stdio.h> #include <algorithm> using namespace std; struct dat { int level; int visit; }data[3200]; bool cmp(dat a, dat b) { return a.level > b.level; } int main() { i

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 #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

HDU 4882 ZCC Loves Codefires(贪心水)

HDU 4882 ZCC Loves Codefires 题目链接 题意:给定一些任务,每个任务有e,k,e表示完成需要时间,k表示完成后消耗,为完成时间t * k,求一个顺序使得完成消耗最少 思路:贪心,知道k大的尽量早晚餐,t小的尽量早完成,所以t / k小的尽量早完成,排个序即可 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int

CodeForces 707A Brain&#39;s Photos (水题)

题意:给一张照片的像素,让你来确定是黑白的还是彩色的. 析:很简单么,如果有一种颜色不是黑白灰,那么就一定是彩色的. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #i

Codeforces 828B Black Square(简单题)

Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n?×?m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum pos