http://www.lydsy.com/JudgeOnline/problem.php?id=1857

好神奇的三分。。

第一次写三分啊sad。。看了题解啊题解QAQ

首先发现无论怎么走一定是在AB和CD上选了两个点然后走的(包括ABCD四个点),所以我们就是要找出这两个点就行了。

且AB上有且只有一个最优点,而每一个AB上的点也对应CD唯一一个最优点orz。

所以我们三分AB上的点(酷炫但是不知道为啥这是个单峰函数orz),然后对应三分CD上的点(这个比前面的好证。。这个初中就学了的吧。sad)然后就行了。。

距离和费用就是三段的和。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const double eps=1e-3;
int ax, ay, bx, by, cx, cy, dx, dy;
double P, Q, R;
double dis(double x1, double y1, double x2, double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); }
double cal(double x, double y) {
double x1, x2, y1, y2, lx=cx, ly=cy, rx=dx, ry=dy;
while(abs(rx-lx)>eps || abs(ry-ly)>eps) {
x1=lx+(rx-lx)/3; y1=ly+(ry-ly)/3;
x2=lx+(rx-lx)/3*2; y2=ly+(ry-ly)/3*2;
double d1=dis(x1, y1, x, y)/R+dis(x1, y1, dx, dy)/Q;
double d2=dis(x2, y2, x, y)/R+dis(x2, y2, dx, dy)/Q;
if(d1<d2) rx=x2, ry=y2;
else lx=x1, ly=y1;
}
return dis(x, y, ax, ay)/P+dis(lx, ly, x, y)/R+dis(lx, ly, dx, dy)/Q;
}
int main() {
cin >> ax >> ay >> bx >> by >> cx >> cy >> dx >> dy >> P >> Q >> R;
double x1, x2, y1, y2, lx=ax, ly=ay, rx=bx, ry=by;
while(abs(rx-lx)>eps || abs(ry-ly)>eps) {
x1=lx+(rx-lx)/3; y1=ly+(ry-ly)/3;
x2=rx-(rx-lx)/3; y2=ry-(ry-ly)/3;
double d1=cal(x1, y1), d2=cal(x2, y2);
if(d1<d2) rx=x2, ry=y2;
else lx=x1, ly=y1;
}
printf("%.2lf", cal(lx, ly));
return 0;
}

Description

在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段。两条传送带分别为线段AB和线段CD。lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R。现在lxhgww想从A点走到D点,他想知道最少需要走多长时间

Input

输入数据第一行是4个整数,表示A和B的坐标,分别为Ax,Ay,Bx,By 第二行是4个整数,表示C和D的坐标,分别为Cx,Cy,Dx,Dy 第三行是3个整数,分别是P,Q,R

Output

输出数据为一行,表示lxhgww从A点走到D点的最短时间,保留到小数点后2位

Sample Input

0 0 0 100
100 0 100 100
2 2 1

Sample Output

136.60

HINT

对于100%的数据,1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10

Source

【BZOJ】1857: [Scoi2010]传送带(三分)的更多相关文章

  1. bzoj 1857: [Scoi2010]传送带 三分

    题目链接 1857: [Scoi2010]传送带 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 934  Solved: 501[Submit][Stat ...

  2. Bzoj 1857: [Scoi2010]传送带(三分套三分)

    1857: [Scoi2010]传送带 Time Limit: 1 Sec Memory Limit: 64 MB Description 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段 ...

  3. BZOJ 1857: [Scoi2010]传送带

    二次联通门 : BZOJ 1857: [Scoi2010]传送带 /* BZOJ 1857: [Scoi2010]传送带 三分套三分 可能是吧..dalao们都说明显是一个单峰函数 可是我证不出来.. ...

  4. BZOJ 1857: [Scoi2010]传送带(三分套三分)

    Time Limit: 1 Sec Memory Limit: 64 MB Submit: 2549 Solved: 1370 [Submit][Status][Discuss] Descriptio ...

  5. 【BZOJ1857】[Scoi2010]传送带 三分套三分

    [BZOJ1857][Scoi2010]传送带 Description 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度 ...

  6. BZOJ 2131 [scoi2010] 传送带

    @(BZOJ)[三分法] Description 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段. 两条传送带分别为线段AB和线段CD. lxhgww在AB上的移动速度为P,在CD上的移 ...

  7. 洛谷P2571 [SCOI2010]传送带 [三分]

    题目传送门 传送带 题目描述 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移 ...

  8. bzoj1857: [Scoi2010]传送带--三分套三分

    三分套三分模板 貌似只要是单峰函数就可以用三分求解 #include<stdio.h> #include<string.h> #include<algorithm> ...

  9. [BZOJ1857][SCOI2010]传送带-[三分]

    Description 传送门 Solution 三分套三分.代码简单但是证明苦兮兮.. 假如我们在AB上选了一个点G,求到该点到D的最小时间. 图中b与CD垂直.设目前从G到D所耗时间最短的路径为G ...

随机推荐

  1. Java I/O操作汇总

    作者:卿笃军 原文地址:http://blog.csdn.net/qingdujun/article/details/41154807 本文简绍解说了FileWriter.FileReader.Buf ...

  2. FFMpeg框架代码阅读

    http://blog.csdn.net/wstarx/article/details/1572393 FFMPEG源码分析(二) http://www.cnblogs.com/qingquan/ar ...

  3. selenium-Getting Started

    1.1. Simple Usage If you have installed Selenium Python bindings, you can start using it from Python ...

  4. webDriver API——第14部分Color Support

    class selenium.webdriver.support.color.Color(red, green, blue, alpha=1) Bases: object Color conversi ...

  5. PHP过滤器

    这里介绍的过滤器包括: 1.filter_input 2.filter_input_array 3.filter_var 4.filter_var_array 5.filter_has_var 一.查 ...

  6. HDU 1073 Online Judge(字符串)

    Online Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  7. “ResGen.exe”已退出,代码为2 问题处理

    这属于VS2010不能编译.Net3.5的问题 用VS2010创建了一个.Net 3.5的Winform项目,结果编译失败,这个问题也算是第二次碰到了,真纠结···这次不再偷懒了,把解决方法记录下来吧 ...

  8. mongodb - save()和insert()的区别

    遇到_id相同的情况下:insert操作会报错:save完成保存操作 > db.person.find() > db.person.insert({"_id":1,ag ...

  9. Phone

    User-Agent Switcher for Chrome EditThisCookie cornerstone SVN

  10. python字符串操作,以及对应的C#实现

    --IndexOf-- python: inx = str.find("aa") c#: var inx = str.IndexOf("aa"); --Last ...