The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemB:Light Bulb
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的更多相关文章
- 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), ...
- 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 ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- 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 ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 【转载】Kafka High Availability
http://www.haokoo.com/internet/2877400.html Kafka在0.8以前的版本中,并不提供High Availablity机制,一旦一个或多个Broker宕机,则 ...
- Ajax概述
- CSS之图片旋转
主方法为: var Img = function() { var T$ = function(id) { return document.getElementById(id); } var ua = ...
- iOS - 字典(NSDictionary)
1. 字典类型的常用处理 //---------------不可变字典 //1.字典的创建 NSArray *array1 = [NSArray arrayWithObjects:@"zha ...
- iOS开发——打包ipa
首先,保证设备证书和配置文件的正确,Xcode上登陆好自己公司的账号Apple ID 1.选中运行模拟器的位置为硬件设备 2.点击导航栏上的[Product]——[Archive]后编译后弹出如下界面 ...
- OC6_目录及文件的创建
// // main.m // OC6_目录及文件的创建 // // Created by zhangxueming on 15/6/19. // Copyright (c) 2015年 zhangx ...
- (转)linux TOP命令各参数详解【转载】
实时监控或查看系统资源使用情况的工具——TOP top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. 下面详细介绍它的使用方法: ( ...
- JSON的使用
最近在项目中大量的使用了JSON, 发现JSON和XML的功能相近,都是一种数据传输格式.只是与XML相比JSON显得更加轻量级,使用也更加容易. JSON依赖的第三方jar包: commons-be ...
- 【转】 .NET中STAThread和MTAThread
ref:http://blog.csdn.net/dyllove98/article/details/9735955 1 COM中的公寓 本文讨论进程内COM组件.以一个示例直观演示STAThread ...
- linux实现nginx按照日期存储日志
通过shell脚本实现+定时任务+nginx信号管理实现日志按日期存储. 1.编写shell脚本,实现日志按日期存储 #!/bin/bash base_path='/home/wwwlogs/' lo ...