• bzoj1857: [Scoi2010]传送带


    一看就是三分

    然后打个表看了一下 确实有三分性

    由于轨迹是线性的所以目标函数应该是单峰的,虽然会比二次函数偏差一点

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstdlib>
     5 #include<cstring>
     6 #include<string>
     7 
     8 using namespace std;
     9 
    10 void setIO(const string& a) {
    11     freopen((a+".in").c_str(), "r", stdin);
    12     freopen((a+".out").c_str(), "w", stdout);
    13 }
    14 
    15 double ax, ay, bx, by, cx, cy, dx, dy, P, Q, R;
    16 
    17 #include<cmath>
    18 double dis(double x1, double y1, double x2, double y2) {
    19     return hypot(x1 - x2, y1 - y2);
    20 }
    21 
    22 double calc(double x, double y) {
    23     double x1 = cx, y1 = cy, x2 = dx, y2 = dy;
    24     for(int i = 1; i <= 30; i++) {
    25         double mx1 = x1 + (x2 - x1) / 3, my1 = y1 + (y2 - y1) / 3;
    26         double mx2 = x1 + (x2 - x1) / 3 * 2, my2 = y1 + (y2 - y1) / 3 * 2;
    27         double cost1 = dis(x, y, mx1, my1) / R + dis(mx1, my1, dx, dy) / Q;
    28         double cost2 = dis(x, y, mx2, my2) / R + dis(mx2, my2, dx, dy) / Q;
    29         if(cost1 > cost2) x1 = mx1, y1 = my1;
    30         else x2 = mx2, y2 = my2;
    31     }
    32     return dis(x, y, x1, y1) / R + dis(x1, y1, dx, dy) / Q;
    33 }
    34 
    35 int main() {
    36     
    37     cin >> ax >> ay >> bx >> by;
    38 //    if(ax > bx) swap(ax, bx), swap(ay, by);
    39     cin >> cx >> cy >> dx >> dy;
    40 //    if(cx > dx) swap(cx, dx), swap(cy, dy);
    41     cin >> P >> Q >> R;
    42     
    43     double x1 = ax, y1 = ay, x2 = bx, y2 = by;
    44     
    45     for(int i = 1; i <= 30; i++) {
    46         double mx1 = x1 + (x2 - x1) / 3, my1 = y1 + (y2 - y1) / 3;
    47         double mx2 = x1 + (x2 - x1) / 3 * 2, my2 = y1 + (y2 - y1) / 3 * 2;
    48         double cost1 = dis(ax, ay, mx1, my1) / P + calc(mx1, my1);
    49         double cost2 = dis(ax, ay, mx2, my2) / P + calc(mx2, my2);
    50         if(cost1 > cost2) x1 = mx1, y1 = my1;
    51         else x2 = mx2, y2 = my2;
    52     }
    53     
    54     printf("%.2f
    ", dis(ax, ay, x1, y1) / P + calc(x1, y1));
    55     
    56     return 0;
    57 }
  • 相关阅读:
    flex布局
    spring与mybatis三种整合方法
    jquery 、 JS 脚本参数的认识与使用
    SSH框架构建微信公众帐号服务器小技巧
    网页中插入QQ在线功能
    Java中Runnable和Thread的区别
    web.xml的初始化参数
    Struts2中实现Web项目的初始化工作
    使用Spring整合javaMail发用邮件
    java中Commons-fileupload实现上传
  • 原文地址:https://www.cnblogs.com/showson/p/5006605.html
Copyright © 2020-2023  润新知