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-;
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=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
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=;i<=n;i++) scanf("%lf%lf",&s[i].x,&s[i].y),s[i].id=i; if(n==)
{
double ans;
ans=min(sqrt((ax-s[].x)*(ax-s[].x)+(ay-s[].y)*(ay-s[].y))+
sqrt((tx-s[].x)*(tx-s[].x)+(ty-s[].y)*(ty-s[].y))
,
sqrt((bx-s[].x)*(bx-s[].x)+(by-s[].y)*(by-s[].y))+
sqrt((tx-s[].x)*(tx-s[].x)+(ty-s[].y)*(ty-s[].y))
);
printf("%.6lf\n",ans);
return ;
} double ans=;
double g=;
for(int i=;i<=n;i++) g=g+*sqrt((s[i].x-tx)*(s[i].x-tx)+(s[i].y-ty)*(s[i].y-ty)); sort(s+,s++n,cmp1);
ans=min(ans,
g+sqrt((s[].x-ax)*(s[].x-ax)+(s[].y-ay)*(s[].y-ay))
-sqrt((s[].x-tx)*(s[].x-tx)+(s[].y-ty)*(s[].y-ty)));
for(int i=;i<=min(n,);i++) a[sz++]=s[i].id; sort(s+,s++n,cmp2);
ans=min(ans,
g+sqrt((s[].x-bx)*(s[].x-bx)+(s[].y-by)*(s[].y-by))
-sqrt((s[].x-tx)*(s[].x-tx)+(s[].y-ty)*(s[].y-ty)));
for(int i=;i<=min(n,);i++) a[sz++]=s[i].id; sort(s+,s++n,cmp3); for(int i=; i<sz; i++)
{
for(int j=; 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 ;
}
CodeForces 671A Recycling Bottles的更多相关文章
- 【模拟】Codeforces 671A Recycling Bottles
题目链接: http://codeforces.com/problemset/problem/671/A 题目大意: A和B在一张二维平面上,平面上有N个垃圾,垃圾桶只有一个在T,问把所有垃圾全扔进垃 ...
- Codeforces 671A Recycling Bottles(贪心+思维)
题目链接:http://codeforces.com/problemset/problem/671/A 题目大意:给你两个人的位置和一个箱子的位置,然后给出n个瓶子的位置,要求让至少一个人去捡瓶子放到 ...
- 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 ...
随机推荐
- sqlite3结合ios开发
简介: SQLite是遵守ACID的关系数据库管理系统,它包含在一个相对小的C库中.它是D.RichardHipp创建的公有领域项目. 不像常见的客户端/服务器结构范例,SQLite引 ...
- nginx 安装启动
[root@localhost ~]# wget http://nginx.org/download/nginx-0.7.67.tar.gz --2010-09-24 14:48:12-- http: ...
- MySQLdb/mysql-python安装时EnvironmentError: mysql_config not found
代码:root@vpser:~# cd MySQL-python-1.2.3root@vpser:~/MySQL-python-1.2.3# python setup.py install sh: m ...
- Jquery EasyUI中treegrid
Jquery EasyUI中treegrid的中右键菜单和一般按钮同时绑定事件时的怪异事件 InChatter系统开源聊天模块前奏曲 最近在研究WCF,又因为工作中的项目需要,要为现有的系统增加一 ...
- 马丁·福勒-page对象
马丁·福勒-page对象 译者注:这篇文章翻译自马丁·福勒(Martin Flower,对,没错,就是软件教父)官网的一篇文章,原文出处在文底.如果你正在做WEB自动化测试,那么我强烈推荐你看这篇文章 ...
- 使用 Aspose.Cells 实现 excel导入
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- 学习ExpressionTree(做装配脑袋出的练习题)
1 // 第一题:画出下列表达式的表达式树.一开始,您很可能不知道某些操作其实也是表达式(比如取数组的运算符a[2]),不过没有关系,后面的习题将帮你验证这一点. //-a ParameterExpr ...
- Play 起步
*****************jdk下载地址: http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.ta ...
- mac系统及xcode使用的SVN客户端升级
mac系统及xcode使用的SVN客户端升级 当前的SVN版本已经升级到1.8.x了,但mac系统自带的以及xcode使用的SVN客户端版本没有跟着升级,还是1.6.x的版本.为了解决隐藏目录.svn ...
- asp.net中的路由系统
ASP.NET MVC重写了ASP.NET管道HttpModule和处理程序HttpHandler.MVC自定义了MvcHandler实现了Controller的激活和Action的执行.但是在请求到 ...