Codeforces 8D Two Friends 三分+二分+计算几何
题目链接:点击打开链接
题意:点击打开链接
三分house到shop的距离,二分这条斜边到cinema的距离
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
#define ll int
#define N 90
#define Pi 3.1415926535898
#define eps 1e-10
double t1, t2;
struct node{
double x,y;
}c,h,s;
double dist(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double dist(node a,node b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double work(double du){
node x = {s.x*(1-du) + h.x*du, s.y*(1-du)+h.y*du};
double ac = dist(x,c), as = dist(x,s), ah = dist(x,h);
if(ac+ah<=t2&&ac+as<=t1)return min(t2-ah,t1-as);
double l = 0, r = 1.0;
for(int i = 1; i <= 300 ; i++){
double mid = (l+r)/2;
node b = {c.x*(1-mid)+x.x*mid,c.y*(1-mid)+x.y*mid};
double bc = dist(b,c), bs = dist(b, s), bh = dist(b, h);
if(bc+bh<=t2 && bc+bs<=t1) l = mid;
else r = mid;
}
node b = {c.x*(1-l)+x.x*l, c.y*(1-l)+x.y*l};
return dist(b,c);
}
int main(){
ll i, j, u, v;
while(cin>>t1>>t2){
cin>>c.x>>c.y;
cin>>h.x>>h.y;
cin>>s.x>>s.y;
double a = dist(c,s), b = dist(c,h), c = dist(h,s); if(b+t2>=a+c){printf("%.8lf\n",min(a+t1+c,b+t2));continue;}
t1+=a+eps; t2+=b+eps;
double l = 0, r = 1.0, ans = 0;
for(i = 1; i <= 300; i++){
double mid1 = (l+r)/2.0, mid2 = (mid1+r)/2.0;
double ans1 = work(mid1), ans2 = work(mid2);
if(ans1<ans2) l = mid1;
else r = mid2;
ans = max(ans, max(ans1,ans2));
}
printf("%.8lf\n",ans);
}
return 0;
}
Codeforces 8D Two Friends 三分+二分+计算几何的更多相关文章
- CF 8D Two Friends (三分+二分)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意 :有三个点,p0,p1,p2.有两个人ali ...
- HDU 2298 Toxophily(公式/三分+二分)
Toxophily Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- CF 8D Two Friends 【二分+三分】
三个地点构成一个三角形. 判断一下两个人能否一起到shop然后回家,如果不能: 两个人一定在三角形内部某一点分开,假设沿着直线走,可以将问题简化. 三分从电影院出来时候的角度,在对应的直线上二分出一个 ...
- Codeforces 939E Maximize ( 三分 || 二分 )
题意 : 给出两个操作,① 往一个序列集合(初始为空)里面不降序地添加数字.② 找出当前序列集合的一个子集使得 (子集的最大元素) - (子集的平均数) 最大并且输出这个最大差值 分析 : 首先关注 ...
- codeforces#403—B题(二分,三分)
B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megab ...
- codeforces 590B B. Chip 'n Dale Rescue Rangers(二分+计算几何)
题目链接: B. Chip 'n Dale Rescue Rangers time limit per test 1 second memory limit per test 256 megabyte ...
- codeforces 8D Two Friends 二分+ 判断三个圆是否有公共交点
题目链接 有两个人x, y, 现在在A点, x要直接去B点, y要先去C点在去B点, 现在给出x, y两人可以行走的最大距离T1, T2, 求出他们从A点出发之后, 可以走的最长的公共路径. 我们先看 ...
- [Codeforces 8D] Two Friends
Brief Introduction: 有两人a.b,他们都在A点,a经过B点到C点,而b直接到C点.a走过的距离不超过la,b走过距离不超过lb,询问他们可能经过最长的公共距离. Algorithm ...
- CodeForces 377B---Preparing for the Contest(二分+贪心)
C - Preparing for the Contest Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
随机推荐
- [UOJ348]州区划分
设$f_i$表示选状态为$i$的点的答案,$s_i$表示状态为$i$的点权和,$不存在欧拉回路g_i=[i\,不存在欧拉回路]s_i$ 那么$f_i=\sum\limits_{j\subset i}\ ...
- 【Splay】bzoj3223 Tyvj 1729 文艺平衡树
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #i ...
- 让Code First下的数据库的迁移更加简单
Code First给我们的程序开发带了很多便利,之前的版本中一个比较不大方便的地方是数据库迁移,麻烦不说,往往还和上下文相关,在不同的版本之间的数据库进行迁移还很容易失败,并且一旦失败还不大容易找到 ...
- How do I find what queries were executing in a SQL memory dump?-----stack
https://blogs.msdn.microsoft.com/askjay/2010/10/03/how-do-i-find-what-queries-were-executing-in-a-s ...
- gitHub 基础命令
设置开发人员信息 git config --global user.name "chen" git config --global user.email "xxxxx@q ...
- [转] Download Images from Multiple Maps
转载自 李旭, Tool: Download Images from Multiple Maps Summary SAS Planet是一款俄罗斯绿色免费软件,一直持续不断更新.该软件最大的一个特点就 ...
- Java构造和解析Json数据的两种方法详解一——json-lib
转自:http://www.cnblogs.com/lanxuezaipiao/archive/2013/05/23/3096001.html 在www.json.org上公布了很多JAVA下的jso ...
- 关于单例模式的N种实现方式
在开发中经常用到单例模式,单例模式也算是设计模式中最容易理解,也是最容易手写代码的模式,所以也常作为面试题来考.所以想总结一下单例模式的理论知识,方便同学们面试使用. 单例模式实现的方式只有两种类型, ...
- 【LaTeX】E喵的LaTeX新手入门教程(2)基础排版
换了块硬盘折腾了好久..联想的驱动真坑爹.前情回顾[LaTeX]E喵的LaTeX新手入门教程(1)准备篇文档框架嗯昨天我们已经编写了一个最基本的文档,其内容是这样的:\documentclass{ar ...
- javascript常用排序算法实现
毕业后,由于工作中很少需要自已去写一些排序,所以那些排序算法都忘得差不多了,不过排序是最基础的算法,还是不能落下啦,于是找了一些资料,然后用Javascript实现了一些常用的算法,具体代码如下: & ...