投影用ライトBulb(3点)

5470 ワード

最近友达のいくつかの文章は投影に変える文章を紹介しました.関連文章の住所
     http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203
    
Light Bulb
Time Limit: 1 Second      Memory Limit: 32768 KB
Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, thinking of how to earn more money. One day, he found that the length of his shadow was changing from time to time while walking between the light bulb and the wall of his house. A sudden thought ran through his mind and he wanted to know the maximum length of his shadow.
用于和投影
Input
The first line of the input contains an integer T (T <= 100), indicating the number of cases.
Each test case contains three real numbers H, h and D in one line. H is the height of the light bulb while h is the height of mildleopard. D is distance between the light bulb and the wall. All numbers are in range from 10-2 to 103, both inclusive, and H- h >= 10-2.
Output
For each test case, output the maximum length of mildleopard's shadow in one line, accurate up to three decimal places..
Sample Input
 
3
2 1 0.5
2 0.5 3
4 3 4

 
Sample Output
 
1.000
0.750
4.000

 
Author:
 
GUAN, Yao
Source:
 
The 6th Zhejiang Provincial Collegiate Programming Contest
Submit
    
Status
 
    毎日同じ理屈
すべての人の心の中で、すべてかつてあれらの懐かしい人に滞在したことがあって、まだいるかも知れなくて、とっくに消えて、茫漠とした人の海の中で失って、そこで、あの懐かしさは寂しくて、ぼんやりした記憶の中でただ1つの“空っぽの殻”だけが残っているため、何もなくて、甚だしきに至っては自分の心さえ入れられなくて、時間はすべてを平らにして、当日の涙を封鎖して、すでにないため、懐かしくて悲しいだけ!
      
    解析:三分法で解く:
     
  三分法と二分法
    1.共通点:
    いずれも、ある区間でターゲット値を検索するために使用されます.通常は最小値、最大値、ターゲット値などです.
    2.相違点:
    二分法:退屈な関数に使用され、一般的に増加または減少関数のタイプを指す.
    三分法:凸関数、例えば;y=x^2関数タイプ、極値を求めるために使用
    以下はテンプレートです.
    Eps=1e-10;
    Double  cale(double x )
    {}
    二分法検索:
    Double  solve(double  low,double  high,double V){
    Int mid;
    While(low+eps {
  Mid=(low+high)/2.0;
    If(cale(mid)>V)
    High=mid;
    Else
    Low=mid;
 }
    Return low;
    }
    三分法:
    double solve(double l,double r)
    {
    double m;
    double mm;
    while(l+ep    {
        m=(l+r)/2.0;
        mm=(m+r)/2.0;
        if(lenth(m)>lenth(mm)//最大値をとる(最小値をとると(length(m)         r=mm;
         else
         l=m;
    }
    return l;
    }
     
    ここで最大シャドウの長さを求めて、似たような三角形から求めることができます
    L/(x+L)=h/H、L=(h*x)/(H-h)
    2つのケースに分けられます.
    一、全体投影が地上:即ちx+L<=Dであると出力長がLとなる
    二、地面と壁に投げました. L 1=(D*h-D*H+H*x)/x;//壁投影(似たような三角形から得られる)
    出力長:D-x+L 1
    
#include<string.h>

#include<stdio.h>

#include<math.h>

#include<algorithm>

#include <iostream>

using namespace std;

const double ep=1e-10;

double H,h,D;

double lenth(double x)

{

    double L,L1;

    L=(h*x)/(H-h);//          

    if(x+L<=D)//         

     return L;

    L1=(D*h-D*H+H*x)/x;//    

    return D-x+L1;

}


double solve(double l,double r)

{

    double m;

    double mm;

    while(l+ep<r)//     

    {

        m=(l+r)/2.0;

        mm=(m+r)/2.0;

        if(lenth(m)>lenth(mm))//    

         r=mm;

         else

         l=m;

    }

    return l;

}

int main()

{

    int T;

    double L;

    scanf("%d",&T);

    while(T--)

    { scanf("%lf%lf%lf",&H,&h,&D);

            L=lenth(solve(0,D));

            printf("%.3lf
",L); } return 0; }

      
文章は终わってみんなに次のプログラマーのいくつかのジョークの语录を分かち合います:多くのいわゆる牛人もただこのようにして、あなたを离れて、マイクロソフトはまだマイクロソフトで、GoogleはまだGoogleで、アップルはやはりアップルで、大雪はやはり大雪で、これらの牛人は会社を离れて、自分は何もありません.
-------------------------------------------------------------------------------------------------------------------