zoukankan      html  css  js  c++  java
  • zoj 3023 Light Bulb

    题目大意:

    求L的最大值

    思路:

    可以想象出是一个关于人到灯泡距离x的单峰上凸函数

    当光线在墙角左边的时候影子在不断增长

    然后通过相似可以推出人在墙上影子的长度为:H+D*(h-H)/x

    再加上地上的D-x就可以计算出每个x的函数值了

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstdlib>
     5 #include<cstring>
     6 #include<algorithm>
     7 #include<vector>
     8 #include<queue>
     9 #define inf 2139062143
    10 #define ll long long
    11 #define MAXN 1001000
    12 #define eps 1e-4
    13 using namespace std;
    14 inline int read()
    15 {
    16     int x=0,f=1;char ch=getchar();
    17     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
    18     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
    19     return x*f;
    20 }
    21 double H,h,d;
    22 double calc(double x){return H+(h*d-H*d)/x+d-x;}
    23 int main()
    24 {
    25     int T=read();
    26     while(T--)
    27     {
    28         scanf("%lf%lf%lf",&H,&h,&d);
    29         double r=d,l=d-h*d/H,ml,mr;
    30         while(r-l>eps)
    31         {
    32             ml=(r-l)/3.0+l,mr=2*(r-l)/3.0+l;
    33             if(calc(ml)>calc(mr)) r=mr;
    34             else l=ml;
    35         }
    36         printf("%.3lf
    ",calc(r));
    37     }
    38 }
    View Code
  • 相关阅读:
    一些常用的接口地址
    1-项目启动
    事件处理优化
    如何javascript获取css中的样式
    mysql编程--创建函数出错的解决方案
    mysql编程---函数
    mysql---数据控制语言(用户及其权限管理)
    php与mysql的常规使用
    php数组的使用
    php函数的使用
  • 原文地址:https://www.cnblogs.com/yyc-jack-0920/p/9246786.html
Copyright © 2011-2022 走看看