http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203

题意:求影子的最长长度L;

当灯,人头和墙角成一条直线时(假设此时人站在A点),此时的长度是影子全在地上的最长长度。当人再向右走时,影子开始投影到墙上,当人贴着墙,影子长度即为人的高度。所以当人从A点走到墙,函数是先递增再递减,为凸性函数,所以我们可以用三分法来求解。

我们假设:人距离灯的水平距离为x,则不难推出:随着x的变化,L = D - x + H - D * (H - h) / x; 是先增后减函数。

我们立足于求其最大值。

x的初始值我们可以假设为:D - D*h/H,因为从0开始到此,L肯定是递增的,所以不必考虑先前的。

x最大值为D:

题解参考:http://blog.csdn.net/niuox/article/details/8529986

三分法详细介绍:http://www.debug4.me/Algorithm/ternary-search/

 #include<bits/stdc++.h>
using namespace std; double H,h,D;
double aa(double x) {
return (h-x)*D/(H-x)+x;
}
int main() {
double l,r,m,mm;
int t;
scanf("%d",&t);
while(t--) {
scanf("%lf%lf%lf",&H,&h,&D);
l=D-D*h/H;
r=h;
while(l+1e-<r) {
m=(l+r)/;
mm=(m+r)/;
if(aa(m)>aa(mm))
r=mm;
else
l=m;
}
printf("%.3lf\n",aa(l));
}
return ;
}

The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemB:Light Bulb的更多相关文章

  1. The 6th Zhejiang Provincial Collegiate Programming Contest->Problem I:A Stack or A Queue?

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3210 题意:给出stack和queue的定义,一个是先进后出(FILO), ...

  2. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...

  3. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  4. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...

  5. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...

  6. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Convert QWERTY to Dvorak

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5502  The 12th Zhejiang Provincial ...

  7. zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5500 The 12th Zhejiang Provincial ...

  8. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Demacia of the Ancients

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5504  The 12th Zhejiang Provincial ...

  9. zjuoj The 12th Zhejiang Provincial Collegiate Programming Contest Ace of Aces

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5493 The 12th Zhejiang Provincial ...

  10. 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第二部分)

    Floor Function Time Limit: 10 Seconds      Memory Limit: 65536 KB a, b, c and d are all positive int ...

随机推荐

  1. C#数组比较取值

    string strs = string.Empty;            string[] strArray1 = { "a", "b", "c& ...

  2. opencv for android sample导入有误

    我们下载好opencv for android 后导入eclipse的时候发现人脸检测还有一个sample项目会有小叉,但是好像没有文件有问题.这时我们该怎么办呢? 在window中: 我们右键选择p ...

  3. 转 DevExpress-ASPxPageControl 动态添加 TabPage 内容

    话不多说想看代码,在细说. 前台,很简单.主要看后台 </dx:ASPxPageControl> 后台,注意注释说明. private void GetUserAttendCellsNew ...

  4. button按钮在IE6、7、8、9、10中处理方式并不相同[转]

    http://msdn.microsoft.com/en-us/library/ms534696%28v=vs.85%29.aspx 转自:http://my.oschina.net/fz04003/ ...

  5. display的小故事

    实在是想不出来到底整个什么题目好..姑且先整这个吧.. 本文不是讲解display这个牛逼css属性的(讲不好才是真的!),主要是分享一下一些小Tips. display:table-cell wid ...

  6. css3学习笔记之渐变

    CSS3 线性渐变 语法 background: linear-gradient(direction, color-stop1, color-stop2, ...); 1 2 3 4 5 6 7 8 ...

  7. jCallout 实现气泡提示

    在提交表单前.焦点转移后或者 keyup 时往往需要对输入的文本就行检验,如果输入内容不符合相关约定则要进行提示或警告,有一个叫 jCallout 的插件可以轻松实现该功能,该插件基于  jQuery ...

  8. Codevs 5126 推销员 2015年NOIP全国联赛普及组

    5126 推销员 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 阿明是一名推销员,他奉命到螺丝街推销他们公司的产品.螺丝街是一条死 ...

  9. C语言中格式化输出的转换说明的fldwidth和precision解析

    首先说什么是C语言的格式化输出,就是printf和它的几个变种(grep -E "v?(sn|s|f)printf").像这些函数都有一个参数format,format中可以加点转 ...

  10. thinkphp3.2引入php 实例化类

    如果你的类库没有采用命名空间的话,需要使用import方法先加载类库文件,然后再进行实例化,例如:我们定义了一个Counter类(位于Com/Sina/Util/Counter.class.php): ...