ZOJ_3203_LightBulb
2016-02-18 20:40
477 查看
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
Sample Output
Author: GUAN, Yao
Source: The 6th Zhejiang Provincial Collegiate Programming Contest
题目意思求如图所示的影子最大长度
显然当影子到达墙壁弯折之前的任意状态长度不如刚好到达墙壁时
影子到达墙壁后 墙壁上的影子变长
而地上的影子变短
因此影子长度应该为一个凸函数,三分求最大值就可以了
这里选取了人与灯的水平距离x为变量
这个题目精度要设置的高些 1e-8WA了一发……
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
题目意思求如图所示的影子最大长度
显然当影子到达墙壁弯折之前的任意状态长度不如刚好到达墙壁时
影子到达墙壁后 墙壁上的影子变长
而地上的影子变短
因此影子长度应该为一个凸函数,三分求最大值就可以了
这里选取了人与灯的水平距离x为变量
这个题目精度要设置的高些 1e-8WA了一发……
#include <iostream> #include <stdio.h> #include <math.h> using namespace std; const double AC=1e-9; double H,h,D; double f(double x) { double s1=H*x/(H-h); double s2=(s1-D)*H/s1; return D-x+s2; } double ts() { double lo=(H-h)*D/H,hi=D; double mid,midmid; while(hi-lo>AC) { mid=(lo+hi)/2; midmid=(mid+hi)/2; //cout<<"ts "<<mid<<" "<<midmid<<endl; if(f(mid)>f(midmid)) hi=midmid; else lo=mid; //cout<<endl; } return f(lo); } int main() { int t; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf",&H,&h,&D); printf("%.3lf\n",ts()); } return 0; }
相关文章推荐
- windows客户端开发--使你的客户端运行时记住上次关闭的大小和位置
- 凸包问题-蛮力法
- Linux笔记(4)——命令基本格式与文件处理命令
- 学习gtest笔记<1-VS2013环境搭建>
- oracle面试题
- 框架跟设计模式的区别
- iOS 在 ARC 环境下 dealloc 的使用、理解误区
- mysql之复制
- 802.11中OFDM中的CP设置以及覆盖范围
- ios- POST数据加密-安全
- 双摄像头立体成像(三)-畸变矫正与立体校正
- 比淘宝更接地气?农村市场为何爱上微商
- [转载]python的常用代码模板
- iOS多线程学习-NSThread、Cocoa NSOperation、GCD
- 关于MVC的理解
- [转载]存储过程
- 生成函数
- [POJ 3164][最小树形图]
- Unity3d 开发(八)复制内容到剪切板
- 修改nopCommerce中的实体