bzoj 1857: [Scoi2010]传送带 三分

题目链接

1857: [Scoi2010]传送带

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 934  Solved: 501
[Submit][Status][Discuss]

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

三分套三分就可以了

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9+7;
const int inf = 1061109567;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
double xa, xb, xc, xd, ya, yb, yc, yd, p, q, r;
double dis(double x1, double y1, double x2, double y2) {
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double ternary(double x, double y) {
    double lx = xc, ly = yc, rx = xd, ry = yd;
    while(fabs(rx-lx)>eps || fabs(ry-ly)>eps) {
        double x1 = lx+(rx-lx)/3, x2 = lx+(rx-lx)/3*2;
        double y1 = ly+(ry-ly)/3, y2 = ly+(ry-ly)/3*2;
        double tmp1 = dis(x, y, x1, y1)/r+dis(x1, y1, xd, yd)/q+dis(x, y, xa, ya)/p;
        double tmp2 = dis(x, y, x2, y2)/r+dis(x2, y2, xd, yd)/q+dis(x, y, xa, ya)/p;
        if(tmp1>tmp2) {
            lx = x1, ly = y1;
        } else {
            rx = x2, ry = y2;
        }
    }
    return dis(x, y, lx, ly)/r+dis(lx, ly, xd, yd)/q+dis(x, y, xa, ya)/p;
}
double solve() {
    double lx = xa, rx = xb, ly = ya, ry = yb;
    while(fabs(rx-lx)>eps || fabs(ry-ly)>eps) {
        double x1 = lx+(rx-lx)/3, x2 = lx+(rx-lx)/3*2;
        double y1 = ly+(ry-ly)/3, y2 = ly+(ry-ly)/3*2;
        double tmp1 = ternary(x1, y1), tmp2 = ternary(x2, y2);
        if(tmp1>tmp2) {
            lx = x1, ly = y1;
        } else {
            rx = x2, ry = y2;
        }
    }
    return ternary(lx, ly);

}
int main()
{
    cin>>xa>>ya>>xb>>yb>>xc>>yc>>xd>>yd>>p>>q>>r;
    double ans = solve();
    printf("%.2f\n", ans);
    return 0;
}
时间: 2024-08-01 10:46:14

bzoj 1857: [Scoi2010]传送带 三分的相关文章

【BZOJ 1857】 [Scoi2010]传送带

1857: [Scoi2010]传送带 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 737 Solved: 387 [Submit][Status][Discuss] Description 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxhgww想从A点走到D点,他想知道最少需要走多长时间 Input 输入数

【BZOJ-1857】传送带 三分套三分

1857: [Scoi2010]传送带 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 1077  Solved: 575[Submit][Status][Discuss] Description 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxhgww想从A点走到D点,他想知道最少需要走多长时间 Input 输入

P2571 [SCOI2010]传送带——hyl天梦

P2571 [SCOI2010]传送带题解----天梦 如写的不好,请多见谅. 对于这道题,我首先想说,确实困惑了我好久,看网上的各种题解,却都不尽人意,思路早已明白,却不会操作.最后想想,还是觉得自己试着写一个吧.一种思路,与题解的思路不同,但理论上可行,但我当时似乎也不太相信那所谓的"理论",毕竟自己错过许多次,即使这样仍要相信自己吗?想着,便已经翻到了我所需要的--与自己思路相同的题解.网址是https://blog.csdn.net/qq_42920122/article/de

bzoj 1858: [Scoi2010] 序列操作 题解

[原题] 1858: [Scoi2010]序列操作 Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 1031  Solved: 529 [Submit][Status] Description lxhgww最近收到了一个01序列,序列里面包含了n个数,这些数要么是0,要么是1,现在对于这个序列有五种变换操作和询问操作: 0 a b 把[a, b]区间内的所有数全变成0 1 a b 把[a, b]区间内的所有数全变成1 2 a b 把[a,b]区间内

BZOJ 1857 传送带 (三分套三分)

在一个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,ROutput输出数据为一行,表示lxhgww从A点走到D点的最短时间,保留

传送带(bzoj 1857)

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

BZOJ 1857 传送带

三分套三分. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define eps 1e-4 using namespace std; double x,y,v1,v2,v0; struct point { double x,y; point (double x,double y):x(x),y(y) {} poi

【BZOJ 1857】【SCOI 2010】传送带

三分套三分,虽然简单,但是也得掌握,,, 时间复杂度$O(log_{1.5}^2 n)$ 一开始WA好几次发现是快速读入里没有return,这样也能过样例? #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const double eps = 1e-3; int in() { int k = 0, fh = 1; char

BZOJ 1857 SCOI 2010 传送带 三分法

题目大意:给出平面上两条线段,在这两条线段上走有一定的速度,在其他的平面上走也有一定的速度,问从A点到D点最少需要多少时间. 思路:好像是三分吧,大概感受一下吧,反正也不会证. CODE: #include <cmath> #include <cstdio> #include <iomanip> #include <cstring> #include <iostream> #include <algorithm> #define EP