【模拟】Codeforces 671A Recycling Bottles
题目链接:
http://codeforces.com/problemset/problem/671/A
题目大意:
A和B在一张二维平面上,平面上有N个垃圾,垃圾桶只有一个在T,问把所有垃圾全扔进垃圾桶最少走多远。一次只能拿一个垃圾。允许一个人走另一个人停下来。
(1 ≤ n ≤ 100 000) (0 ≤ xi, yi ≤ 109)
题目思路:
【模拟】
因为每次只能携带一个垃圾,大部分垃圾都是人扔完上一个垃圾后,从垃圾桶出发去捡的。
而最多有两个垃圾不是被人从垃圾桶出发完再扔到垃圾桶。
可以先将答案算作都从垃圾桶开始往返捡的距离,再枚举哪一个垃圾被人直接走过去捡能优化答案。注意不要让两个人都选择同一个垃圾。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 100004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
double anss;
struct xxx
{
LL x,y;
double disa,disb,dist;
}q[N],a,b,t;
double dis(xxx aa,xxx bb)
{
return sqrt(sqr(aa.x-bb.x)+sqr(aa.y-bb.y));
}
bool cmp(xxx aa,xxx bb)
{
return aa.dist<bb.dist;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,ma,mb;
double ax,ay,bx,by,z;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
while(~scanf("%I64d",&a.x))
// while(~scanf("%d",&n))
{
anss=;ay=by=;
scanf("%I64d%I64d%I64d%I64d%I64d",&a.y,&b.x,&b.y,&t.x,&t.y);
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%I64d%I64d",&q[i].x,&q[i].y);
q[i].disa=dis(a,q[i]);
q[i].disb=dis(b,q[i]);
q[i].dist=dis(t,q[i]);
}
sort(q+,q++n,cmp);
anss=q[].dist+q[].dist;
ax=q[].dist-q[].disa;
bx=q[].dist-q[].disb;
ma=mb=;
for(i=;i<=n;i++)
{
anss+=q[i].dist+q[i].dist;
z=q[i].dist-q[i].disa;
if(ax<z)
{
ay=max(ax,ay);
ax=z;
ma=i;
}
else ay=max(ay,z);
z=q[i].dist-q[i].disb;
if(bx<z)
{
by=max(bx,by);
bx=z;
mb=i;
}
else by=max(by,z);
}
if(ma!=mb)z=ax+bx;
else z=max(ax+by,bx+ay);
z=max(z,ax);
z=max(z,bx);
printf("%.12lf\n",anss-z);
}
return ;
}
/*
// //
*/
【模拟】Codeforces 671A Recycling Bottles的更多相关文章
- Codeforces 671A Recycling Bottles(贪心+思维)
题目链接:http://codeforces.com/problemset/problem/671/A 题目大意:给你两个人的位置和一个箱子的位置,然后给出n个瓶子的位置,要求让至少一个人去捡瓶子放到 ...
- CodeForces 671A Recycling Bottles
暴力. 每个人找到一个入口,也就是从回收站到这个入口走的路程由人的位置到入口的路程来替代. 因此,只要找两个人分别从哪里入口就可以了.注意:有可能只要一个人走,另一人不走. #pragma comme ...
- codeforces 672C - Recycling Bottles 贪心水题
感觉很简单,就是讨论一下 #include <stdio.h> #include <string.h> #include <algorithm> #include ...
- Codeforces Recycling Bottles 模拟
C. Recycling Bottles time limit per test: 2 seconds memory limit per test: 256 megabytes input: stan ...
- Codeforces Round #352 (Div. 1) A. Recycling Bottles 暴力
A. Recycling Bottles 题目连接: http://www.codeforces.com/contest/671/problem/A Description It was recycl ...
- 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 Centr ...
- codeforces 352 div 2 C.Recycling Bottles 贪心
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 671 A——Recycling Bottles——————【思维题】
Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #352 (Div. 2) C. Recycling Bottles
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- 安卓数据存储(2):SharedPreferences
SharedPreferences是Android中最容易理解的数据存储技术,实际上SharedPreferences处理的就是一个key-value(键值对)在读取数据时可以通过这个键把相应的值取出 ...
- php获得访问来源(手机wap访问、电脑web访问)
为了更好的用户体验,本主题默认支持wap和web两种访问样式,wap访问将不包含任何脚本.样式也是重新撰写,不支持更多页面,只支持首页.详情页, 评论框.登录等内容将陆续更新到wap内容里.如果想测试 ...
- node基础再现--module.exports 和exports
实际上,最最基础的方法,最最原始的方法是module.exports,至于exports,是为了方便书写才出来的,应该说,module.exports 包含exports,所工作的范围更加的广泛! m ...
- PetaPoco 存储过程
1 执行不带参数的存储过程 public List<dynamic> ceshiProc() { string sql = @"EXEC [dbo].[p_ceshi1]&quo ...
- 那些年,我们一起学WCF--(6)PerCall实例行为
当客户端调用服务器端服务后,服务器端就会为客户端生成一个实例,关于服务实例的分配问题,在WCF中有专门的属性进行设置,可以让所有客户端共享一个实例, 也可以让一个客户端可以拥有多个实例,也可以让一个实 ...
- php验证是否为手机端还是PC
<?php $forasp = strtolower($_SERVER['HTTP_USER_AGENT']); if(strpos($forasp,'mobile')==true) { ech ...
- Android学习笔记(广播机制)
1.Android的广播机制介绍 收听收音机也是一种广播,在收音机中有很多个广播电台,每个广播电台播放的内容都不相同.接受广播时广播(发送方)并不在意我们(接收方)接收到广播时如何处理.好比我们收听交 ...
- ASP.NET 导入EXCEL文档
鉴于教务一般都是手动输入学生信息,在未了解本校数据库的客观情况之下,我们准备设计一个导入excel文档中学生信息如数据库的功能.结合网上各类大牛的综合版本出炉.. 首先具体的实现思想如下: 1.先使用 ...
- JDBC标准事物编程模式
事物简介: 事物是一种数据库中保证交易可靠的机制,JDBC支持数据库中事物的概念,默认情况下事物是默认提交的. 事物的特性: 1.事物必须是原子工作单元,对于其数据的修改,要么都执行,要么都不执行2. ...
- Codeforces 441D Valera and Swaps(置换群)
题意: 给定一个1~n的排列(n<=3000),输出字典序最小且次数最少的交换操作,使得操作后的排列可以通过最少m次交换得到排列[1,2,...n] Solution: 可以将排列的对应关系看做 ...