Light Bulb ZOJ - 3203 三分
三分:
和二分非常类似的一个算法,与二分不同的是
二分是单调的,而三分是一个先增后减或者先减后增
三分可以求出峰值。
注意三分一定是严格单调的,不能有相等的情况。
讲个例题:
题意:
一个人发现他的影子的长度随着他在灯泡和墙壁之间走到时发生着变化。一个突然的想法出现在脑海里,他想知道他的影子的最大长度。
例图:

输入格式
输入文件的第一行包含一个整数 ,表示测试数据的组数。
对于每组测试数据,仅一行,包含三个实数 , 和 , 表示灯泡的高度, 表示 mildleopard 的身高, 表示灯泡和墙的水平距离。
输出格式
输出文件共 行,每组数据占一行表示影子的最大长度,保留三位小数。
样例
样例输入
3
2 1 0.5
2 0.5 3
4 3 4
样例输出
1.000
0.750
4.000
题解:

1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<iostream>
4 #include<string.h>
5 #include<algorithm>
6 using namespace std;
7 const int maxn=500005;
8 const int INF=0x3f3f3f3f;
9 const int eps=1e-11;
10 typedef long long ll;
11 double height,high,width;
12 double panduan(double x)
13 {
14 double ans=high/height*width;
15 double dis=width-x; //dis就是人距离墙的距离
16 if(ans-dis>0) //ans就是影子不在墙的上面时它的长度
17 {
18 double z=dis/width;
19 double sum=dis+(z*height-high)/(z-1.0);
20 return sum;
21 }
22 else
23 {
24 return ans;
25 }
26 }
27 int main()
28 {
29 int t;
30 scanf("%d",&t);
31 while(t--)
32 {
33 scanf("%lf%lf%lf",&height,&high,&width);
34 double l=0,r=width; //我的三分是三分的人距离墙的距离
35 while(r - l > 1e-11) //这就是三分模板了,只要确定了三分的上界和下界就可以直接代入使用
36 {
37 double m1 = l + (r - l) / 3;
38 double m2 = r - (r - l) / 3;
39 if(panduan(m1) > panduan(m2)) r = m2;
40 else l = m1;
41 }
42 printf("%.3lf\n", panduan(l));
43 }
44 return 0;
45 }
Light Bulb ZOJ - 3203 三分的更多相关文章
- 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 (三分查找)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- 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
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 ...
- Light Bulb(三分)
ZOJ Problem Set - 3203 Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildl ...
随机推荐
- python模块详解 | progressbar
参考官方文档:https://pypi.org/project/progressbar/#description progressbar 安装: pip install progressbar pro ...
- 彻底搞懂MySQL为什么要使用B+树索引
目录 MySQL的存储结构 表存储结构 B+树索引结构 B+树页节点结构 为什么要用B+树索引 二叉树 多叉树 B树 B+树 搞懂这个问题之前,我们首先来看一下,MySQL表的存储结构 MySQL的存 ...
- 树莓派3B装ubuntu server后开启wifi
树莓派官网选择ubuntu server下载映像 step 1: 使用SDFormatter格式化SD卡: step2: 使用win32diskimager工具将映像写入准备好的SD卡: step3: ...
- Spring Boot 2.x基础教程:配置元数据的应用
在使用Spring Boot开发应用的时候,你是否有发现这样的情况:自定义属性是有高量背景的,鼠标放上去,有一个Cannot resolve configuration property的配置警告. ...
- Java语法糖详解
语法糖 语法糖(Syntactic Sugar),也称糖衣语法,是由英国计算机学家 Peter.J.Landin 发明的一个术语,指在计算机语言中添加的某种语法,这种语法对语言的功能并没有影响,但是更 ...
- 不错的网站压力测试工具webbench
webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好,安装使用也特别方便. 1.适用系统:Linux 2.前期准备:yum install ...
- https://tools.ietf.org/html/rfc8017
PKCS #1: RSA Cryptography Specifications Version 2.2
- promise有几种状态,什么时候会进入catch
三个状态:pending.fulfilled.reject两个过程:padding -> fulfilled.padding -> rejected当pending为rejectd时,会进 ...
- 系列trick - 建图
对偶图 主体思想:平面图的割,等价于对偶图的路 例题:[BeiJing2006]狼抓兔子 网上有114514篇题解,这里不赘述 点变边 主体思想:点带点权,而要在点上实现一些在边上的问题,比如最小割点 ...
- CODEVS 2542单词__fail树
2542 单词 2013年省队选拔赛天津市队选拔赛 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述 Description 小张最近在忙毕 ...