The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemB:Light Bulb
来源:互联网 发布:centos 7开机密码忘记 编辑:程序博客网 时间:2024/05/21 15:38
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-6<r) { m=(l+r)/2; mm=(m+r)/2; if(aa(m)>aa(mm)) r=mm; else l=m; } printf("%.3lf\n",aa(l)); } return 0;}
0 0
- The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemB:Light Bulb
- The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemB:Light Bulb
- The 6th Zhejiang Provincial Collegiate Programming Contest
- The 6th Zhejiang Provincial Collegiate Programming Contest
- The 7th Zhejiang Provincial Collegiate Programming Contest
- The 8th Zhejiang Provincial Collegiate Programming Contest / L - Javabeans
- The 8th Zhejiang Provincial Collegiate Programming Contest / M - Median
- The 8th Zhejiang Provincial Collegiate Programming Contest
- The 9th Zhejiang Provincial Collegiate Programming Contest
- The 5th Zhejiang Provincial Collegiate Programming Contest 部分题解
- The 10th Zhejiang Provincial Collegiate Programming Contest Solution
- The 11th Zhejiang Provincial Collegiate Programming Contest---Talented Chef
- The 11th Zhejiang Provincial Collegiate Programming Contest
- The 11th Zhejiang Provincial Collegiate Programming Contest
- The 11th Zhejiang Provincial Collegiate Programming Contest
- The 11th Zhejiang Provincial Collegiate Programming Contest
- The 12th Zhejiang Provincial Collegiate Programming Contest
- The 12th Zhejiang Provincial Collegiate Programming Contest - A
- Basic C++ Container classes summary(Array, Vector, List)
- 【IntentService】原理解析
- 解决window平台下JNI生成头文件找不到"xxx"类文件
- The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemA:Second-price Auction
- 固定管线shader编写:基本属性
- The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemB:Light Bulb
- c的简单数据组存储
- iOS开发系列--C语言之预处理
- 一篇很全面的freemarker教程
- 15个值得开发人员关注的jQuery开发技巧和心得
- PostCSS一种更优雅、更简单的书写CSS方式
- 基于platform总线的中断(按键)字符设备驱动设计
- spring【7】(spring事务详解)
- Spring MVC 无XML配置入门示例