ZOJ 3203 Light Bulb( 三分求极值 )
**链接:****传送门 **
题意: 求影子长度 L 的最大值
思路:如果 x = 0 ,即影子到达右下角时,如果人继续向后走,那么影子一定是缩短的,所以不考虑这种情况。根据图中的辅助线外加相似三角形定理可以得到 L = D * (h-x)/(H-x) + x , 再经过一些变形后可知这个 L = D * ( H - h )/( x - H ) + ( x - H ) + H + D ,明显的对号函数在左侧的图像,所以一定是个 凸函数 ,用三分求出极值即可
/*************************************************************************
> File Name: zoj3203.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月05日 星期五 18时53分33秒
************************************************************************/
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
using namespace std;
#define eps 1e-6
#define dou double
dou H,h,D;
int T;
dou f(dou x){
return D*(h-x)/(H-x) + x;
}
void solve(){
// 一定要注意边界的选取,不能随意乱选!!
dou l = 0 , r = h , mid , midmid;
while(r-l>eps){
mid = (l+r)/2;
midmid = (mid+r)/2;
if( f(mid)>=f(midmid) ) r = midmid;
else l = mid;
}
dou ans = f((r+l)/2);
// cout<< fixed << setprecision(3) << ans <<endl;
printf("%.3lf\n",ans);
}
int main(){
scanf("%d",&T);
while(T--){
cin>> H >> h >> D;
solve();
}
return 0;
}
ZOJ 3203 Light Bulb( 三分求极值 )的更多相关文章
- ZOJ - 3203 Light Bulb(三分)
题意:灯离地面的高度为$H$,人的身高为$h$,灯离墙的距离为$D$,人站在不同位置,影子的长度不一样,求出影子的最长长度. 思路:设人离灯的距离为$x$,当人走到距离灯长度为$L$时,人在墙上的影子 ...
- ZOJ 3203 Light Bulb (三分+计算几何)
B - Light Bulb Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- 三分 --- ZOJ 3203 Light Bulb
Light Bulb Problem's Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 Mean: ...
- ZOJ 3203 Light Bulb - 求导求最大值
如果L全在地面上: 输出 h * D / H 如果L全在墙上: 输出 h 否则: (D - X ) / X = Y / (H - h) L = D - X + h - Y 然后对L求导即可 #incl ...
- ZOJ 3203 Light Bulb (三分查找)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- zoj 3203 Light Bulb,三分之二的基本问题
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- ZOJ 3203 Light Bulb
Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow a ...
- ZOJ 3203 Light Bulb(数学对勾函数)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- [清华集训2015]灯泡(浙江大学ZOJ 3203 Light Bulb)
Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother ...
随机推荐
- sublime 自定义快捷生成代码块
菜单栏目选 Tools(工具) =>Developer(插件开发)=>New Snippet....(新建代码片段),如图: 接着会新开一个标签页,会附带一些内容:如图: 将“Hello, ...
- awk的总结
入门总结 Awk简介 awk不仅仅时linux系统中的一个命令,而且是一种编程语言,可以用来处理数据和生成报告.处理的数据可以是一个或多个文件,可以是来自标准输入,也可以通过管道获取标准输入,awk可 ...
- RobotFrameWork+APPIUM实现对安卓APK的自动化测试----第三篇【实例】
http://blog.csdn.net/deadgrape/article/details/50579565 在这一篇里我先让大家看一下RF+APPIUM这个框架的实际运行时什么样子的,给大家一个直 ...
- 你必须搞清楚的String,StringBuilder,StringBuffer
String,StringBuilder 以及 StringBuffer 这三个类的关系与区别一直是 Java 的经典问题,这次就来讲一下关于这三个类的一些知识 一. 简单对比 String : 字符 ...
- Tsinsen A1206. 小Z的袜子
/* Tsinsen A1206. 小Z的袜子 http://www.tsinsen.com/new/A1206 BZOJ 2038: [2009国家集训队]小Z的袜子(hose) http://ww ...
- ExtJs之Ext.XTemplate:模板成员函数
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- 开启WIFI
C:\Windows\system32>netsh wlan set hostednetwork mode=allow ssid=wuyechun-wifi k ey= 承载网络模式已设置为允许 ...
- python的urlencode与urldecode
```python3.x中urlencode在urllib.parse模块中``` 当url地址含有中文,或者参数有中文的时候,这个算是很正常了,但是把这样的url作为参数传递的时候(最常见的call ...
- Java进化? Kotlin初探与集成Android项目
欢迎Follow我的GitHub, 关注我的CSDN. Kotlin是基于JVM的编程语言, 由JetBrains公司开发, 眼下已经开源. IntelliJ IDEA, PyCharm, Andro ...
- [HTML5] Semantics for accessibility
For example, when we use checkbox, if we do like this: <div class="inline-control sign-up co ...