zoukankan      html  css  js  c++  java
  • bzoj 1857

    三分,对于单凸的函数(单调的也可以),可以找出最值。

    这道题可以感性认识一下。。。。。。

     1 /**************************************************************
     2     Problem: 1857
     3     User: idy002
     4     Language: C++
     5     Result: Accepted
     6     Time:32 ms
     7     Memory:1272 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11 #include <cmath>
    12 #include <iostream>
    13 #define eps 1e-5
    14 using namespace std;
    15  
    16 int sg( double x ) { return (x>-eps)-(x<eps); }
    17 struct Vector {
    18     double x, y;
    19     Vector(){}
    20     Vector( double x, double y ):x(x),y(y){}
    21     Vector operator+( const Vector & b ) const { return Vector(x+b.x,y+b.y); }
    22     Vector operator-( const Vector & b ) const { return Vector(x-b.x,y-b.y); }
    23     Vector operator*( double k ) const { return Vector(x*k,y*k); }
    24     void read() { scanf( "%lf%lf", &x, &y ); }
    25     double dis() { return sqrt(x*x+y*y); }
    26 };
    27 typedef Vector Point;
    28  
    29 Point A, B, C, D, E1, E2, E, F1, F2, F;
    30 double P, Q, R;
    31  
    32 inline double gettime() {
    33     return (A-E).dis()/P+(F-D).dis()/Q+(E-F).dis()/R;
    34 }
    35 double onCD() {
    36     double t1, t2;
    37     F1 = C, F2 = D;
    38     while( (F1-F2).dis() >= eps ) {
    39         Vector step = (F2-F1)*(1.0/3.0);
    40         F = F1+step;
    41         t1 = gettime();
    42         F = F +step;
    43         t2 = gettime();
    44         if( t1-t2<0.0 ) {
    45             F2 = F2-step;
    46         } else {
    47             F1 = F1+step;
    48         }
    49     }
    50     F = F1;
    51     return gettime();
    52 }
    53 double onAB() {
    54     double t1, t2;
    55     E1 = A, E2 = B;
    56     while( (E1-E2).dis() >= eps ) {
    57         Vector step = (E2-E1)*(1.0/3.0);
    58         E = E1+step;
    59         t1 = onCD();
    60         E = E +step;
    61         t2 = onCD();
    62         if( t1-t2<0.0 ) {
    63             E2 = E2-step;
    64         } else {
    65             E1 = E1+step;
    66         }
    67     }
    68     E = E1;
    69     return onCD();
    70 }
    71 int main() {
    72     A.read();
    73     B.read();
    74     C.read();
    75     D.read();
    76     scanf( "%lf%lf%lf", &P, &Q, &R );
    77     printf( "%.2lf
    ", onAB() );
    78 }
    View Code
  • 相关阅读:
    【Python3】操作文件,目录和路径
    Python中的文件和目录操作实现
    【Python 2 到 3 系列】 此整型非彼整型
    【Python 2 到 3 系列】 print 是函数
    css网页中设置背景图片的方法详解
    (转)开源项目miaosha(下)
    (转)开源项目miaosha(上)
    (转)开源项目t-io
    (转)WebSocket学习
    缓存问题参考
  • 原文地址:https://www.cnblogs.com/idy002/p/4381970.html
Copyright © 2011-2022 走看看