C. Recycling Bottles (几何)

3 篇文章 0 订阅
  • 题目链接:http://codeforces.com/contest/672/problem/C
  • 题意:有两个人,a 和 b ,一个垃圾桶 t,给你他们在二维平面的坐标,和n个空瓶子的坐标,a和b要把这些垃圾放进垃圾桶。保证所有坐标不重合,问a和b总的最小行走距离。
  • 算法:几何
  • 思路:分为三种情况
    • a和b一定都参与——disl
    • 只有a参与————disa
    • 只有b参与————disb

#include <bits/stdc++.h>
#define pi acos(-1.0 )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL , LL>  PLL;
const int INF = 0x3f3f3f3f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;//4e18 ~= 2^62
const int maxn =1e5 + 10;
const LL mod = 998244353;

PLL a, b, t, c[maxn];
double dis(PLL a, PLL b)
{
    return sqrt((a.first-b.first)*(a.first-b.first) + (a.second-b.second)*(a.second-b.second));
}

int main()
{
    scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &a.first, &a.second, &b.first, &b.second, &t.first, &t.second);
    int n; scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%I64d%I64d", &c[i].first, &c[i].second);
    double l = dis(c[1], t);
    double disa = dis(a, c[1]) + l;
    double disb = dis(b, c[1]) + l;
    double disl = min(disa, disb);
    double sum = 2*l;
    for(int i=2; i<=n; i++){
        l = dis(c[i], t);
        disl = min(min(disl+2*l, disa+dis(b, c[i])+l), disb+dis(a, c[i])+l);
        disa = min(disa+2*l, sum+dis(a, c[i])+l);
        disb = min(disb+2*l, sum+dis(b, c[i])+l);
        sum+=2*l;
    }
    cout << fixed << setprecision(15) << min(min(disl,disa), disb) << endl;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值