ZOJ 3203 Light Bulb
2015-08-10 20:38
316 查看
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
相似求公式 三分求结果 不能用二分
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
相似求公式 三分求结果 不能用二分
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; const double eps=1e-8; double H,h,D,ans; double Cal(double l) { return l+D-D*(H-h)/(H-l); } int main() { int t; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf",&H,&h,&D); double left=0,right=h,mid,midmid; while(right-left>=eps) { mid=(left+right)/2; midmid=(mid+right)/2; if(Cal(mid)>Cal(midmid)) right=midmid; else left=mid; } printf("%.3lf\n",Cal(left)); } return 0; }
相关文章推荐
- 内容跟着鼠标跑
- IOS(数据持久化1)
- leetcode 111 —— Pascal's Triangle
- VirtualBox5 端口转发(可视化操作)
- 【SuffixArray】bzoj1717 [Usaco2006 Dec] Milk Patterns 产奶的模式
- JSON for C++ 介绍1
- 真正认识 JFrame 和 getContentPane() 方法
- wget www.baidu.com执行流程分析
- HDU 5167 Fibonacci——BestCoder Round #28(搜索+预处理)
- cocos2d-x手机游戏(IOS版本)接入分享shareSDK(新浪微博和微信分享)记录
- C语言-FunctionPointer
- 二分图匹配学习——匈牙利算法模板
- BZOJ1007
- hdu 5365+hdu 5355
- hdu 2029 Palindromes _easy version(回文串)
- HttpSessionListener接口监听网站在线人数
- SeekBar拖动条的使用
- (二)表的连接与外键约束
- VS2010 添加静态链接库(包括.h文件和.lib文件)以添加jsoncpp为例
- 【COCI 2012】Germ