zoukankan      html  css  js  c++  java
  • 灯泡

    枚举人到墙的距离(x), 根据初中的三角形相似知识很容易推出计算式, 需要注意的是这个计算式有一定范围, 必须要把影子投到墙上, 显然如果不投到墙上, (x)越大影长越小。

    总影长大致是先增后减的, 证明应该是可以推出个二次函数的式子。。。懒得推了, 直接三分便可以。。

    关键是边界。。。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<map>
    #include<queue>
    #include<vector>
    #include<set>
    #include<cmath>
    #include<cstdlib>
    #include<ctime>
    
    using namespace std;
    
    #define FOR(a, b, c) for(int a = b; a <= c; a++)
    
    const int mx = 1e5 + 5;
    const int inf = 1<<30;
    
    void fre() {
    	freopen(".txt", "r", stdin);
    	freopen(".txt", "w", stdout);
    }
    
    double H, h, D;
    
    double calc(double x) {
    //	if(x == D) return 0;
    //	if(h <= x*r) return (h/r);
    	return (h-x*(H-h)/(D-x))+x;
    }
    
    int main(){
        //fre();
        int t; cin >> t;
        while(t--) {
        	cin >> H >> h >> D;
        	double l = 0, r = D*h/H;
        	while(r - l > 0.000001) {
        		double lmid = l+(r-l)/3, rmid = r-(r-l)/3;
        		if(calc(lmid) <= calc(rmid)) l = lmid;
    			else r = rmid; 
    		}
    		printf("%.3lf
    ", calc(l));
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    9.19 数组 冒泡排序和二分法
    9,18 考试
    html5学习拓展
    第七天,
    第六天 js 开始
    第五天 列表 流
    第四天 样式,框架
    硬件攻城狮设计需要考量的11个关键因素
    步进电机的驱动方式
    MOS管防反接电路设计
  • 原文地址:https://www.cnblogs.com/Maktub-blog/p/11373564.html
Copyright © 2011-2022 走看看