题目链接

BZOJ1857

题解

画画图就发现实际上是在\(AB\)上和\(CD\)上分别选两个点\(E\),\(F\),使得\(t_{AE} + t_{EF} + t_{FD}\)最小

然后猜想到当\(E\)固定时,这个值的函数关于\(|CF|\)是下凸的

当\(F\)总取最优时,关于\(|AE|\)也是下凸的

感觉十分的对

两层三分即可

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
struct point{
double x,y;
}A,B,C,D,AB,CD;
inline point operator -(const point& a,const point& b){
return (point){a.x - b.x,a.y - b.y};
}
inline point operator +(const point& a,const point& b){
return (point){a.x + b.x,a.y + b.y};
}
inline point operator *(const double& a,const point& b){
return (point){a * b.x,a * b.y};
}
double dis(const point& a,const point& b){
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double P,Q,R;
double cal2(double lam1,double lam2){
point E = A + lam1 * AB,F = C + lam2 * CD;
return dis(A,E) / P + dis(E,F) / R + dis(F,D) / Q;
}
double cal(double lam){
double l = 0,r = 1,lmid,rmid,len,cl,cr;
while (r - l > 0.00001){
len = r - l;
lmid = l + len / 3;
rmid = r - len / 3;
cl = cal2(lam,lmid); cr = cal2(lam,rmid);
if (cl > cr) l = lmid;
else r = rmid;
}
return cal2(lam,(r + l) / 2);
}
int main(){
scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y,&P,&Q,&R);
AB = B - A; CD = D - C;
double l = 0,r = 1,lmid,rmid,len,cl,cr;
while (r - l > 0.00001){
len = r - l;
lmid = l + len / 3;
rmid = r - len / 3;
cl = cal(lmid); cr = cal(rmid);
if (cl > cr) l = lmid;
else r = rmid;
}
printf("%.2lf\n",cal((l + r) / 2));
return 0;
}

最新文章

  1. 【Swift】UITableViewCell 中 TTTAttributedLabel 超链接无法点击的问题
  2. request response
  3. webpack 教程 那些事儿04-webpack项目实战分析
  4. &lt;转&gt;ORA-06413 连接未打开错误
  5. Struts2(十三)国际化-internationalization
  6. 序列的方法(str,list,tuple)
  7. cocos2d-x实战 C++卷 学习笔记--第4章 字符串 __String类
  8. CSU 1505 酷酷的单词 湖南省赛第十届题目
  9. Cgroup - Linux 内存资源管理
  10. SSH整合缓存之-Memcached作为hibernate的二级缓存
  11. laravel的延迟消息队列
  12. Kubernetes — 控制器
  13. MySQL学习8 - 数据的增删改
  14. Github上36893颗星!这个被称为下一代企业级应用首选技术你学了么?
  15. VMware虚拟机共享宿主机硬盘步骤
  16. day11_python_1124
  17. List根据时间字符串排序
  18. stm32常识
  19. RobotFramework安装指南
  20. Hbase RESTFul API创建namespace返回500

热门文章

  1. Python基础教程学记(1)
  2. aioysql(异步操作MySQL)-python
  3. Python的scrapy之爬取妹子图片
  4. ruby 操作csv
  5. POJ1426 Find The Multiple 解题报告
  6. SEARCH(文字の検索)
  7. DAG上dp思想
  8. Sqoop帮助文档
  9. git删除本地及远程分支
  10. thrift服务端到客户端开发简单示例