【三分】light bulb(zoj3203)
题目描述:
如图,你可以在房间里移动,灯泡的高度为H,你的身高为h,灯泡与墙的水平距离为D,求你影子的最长长度(影子长度=地上影子长度+墙上影子长度)
样例输入:
0.5
0.5
样例输出:
1.000 0.750 4.000
此题是一道三分模板题
用x表示墙上影子的长度,根据相似三角形可以得到地上的影子长度为(h-x)*d/(H-x)
如图:
三分答案求x即可
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; inline int read()
{
int f=,x=;
char ch=getchar();
while(ch<'' || ch>'') {if(ch=='-') f=-; ch=getchar();}
while(ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
} int T;
double H,h,d; double f(double x)
{
return (h-x)*d/(H-x)+x;
} int main()
{
T=read();
while(T--)
{
scanf("%lf%lf%lf",&H,&h,&d);
double l=,r=h;
while(r-l>1e-)
{
double lm=l+(r-l)/,rm=r-(r-l)/;
if(f(lm)>=f(rm)) r=rm;
else l=lm;
}
printf("%.3lf\n",f(r));
}
return ;
}
这是代码
【三分】light bulb(zoj3203)的更多相关文章
- Light Bulb(三分)
ZOJ Problem Set - 3203 Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildl ...
- 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 ...
- A. Light Bulb
A. Light Bulb Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO f ...
- 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 ...
- TOJ 2814 Light Bulb
Description Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house ...
随机推荐
- Java知多少(54)断言详解
断言的概念 断言用于证明和测试程序的假设,比如“这里的值大于 5”.断言可以在运行时从代码中完全删除,所以对代码的运行速度没有影响. 断言的使用 断言有两种方法: 一种是 assert<< ...
- JavaScript高级用法二之内置对象
综述 本篇的主要内容来自慕课网,内置对象,主要内容如下 1 什么是对象 2 Date 日期对象 3 返回/设置年份方法 4 返回星期方法 5 返回/设置时间方法 6 String 字符串对象 7 返回 ...
- Java如何替换所有指定(出现)的字符串?
在Java编程中,如何替换所有指定(出现)的字符串? 以下示例演示如何使用Matcher类的replaceAll()方法替换字符串中的所有出现的子字符串. package com.yiibai; im ...
- RMAN正确地删除Archivelog以及设置有备库的归档删除策略
原文链接:http://blog.sina.com.cn/s/blog_64e166580100xks5.html 如何正确地删除Archivelog: Archivelog并不能直接得从OS层直接物 ...
- php 页面间传递数据
b.php <?php function getClientIP() { if (getenv("HTTP_CLIENT_IP")) $ip = getenv("H ...
- 将Highcharts图表数据生成Table表格
有的时候,我们不仅仅需要漂亮的统计图来显示统计结果,还需要在统计图下方一个表格可以更加直观的展现各类数据.既然统计图都显示出来了,那我们可以根据统计图的各元素生成表格了. 首先,先显示统计图. Htm ...
- oracle学习笔记1(环境搭建)
学习的开始先剧透一下,本人有点笨,本来想用oracle vbox,装个red hat+oracle,但是虚拟机一直报错,0x00000000内存不能written.所以便想到其他的办法,刚好接触了go ...
- linux相关(3)
1. shell环境变量 能够存在于本shell进程及其子shell进程的变量.变量可以从父shell进程传递给子shell进程,而不能反过来,因此环境变量在子shell进程中无论如何修改都不会影响到 ...
- Elasticsearch 学习之不停止服务,完成升级重启维护操作
我们可以设置集群的平衡参数来暂时禁用掉平衡,具体步骤如下: 1.如果可能的话,先暂停掉数据新增和更新操作,这样会提高集群恢复的时间: 2.禁用集群分片平衡操作,直到告诉集群可以恢复平衡操作为止,禁用配 ...
- git 搭建本地仓库
文档 创建仓库 mkdir project cd project/ git init git remote add origin /d/project/.git // 仓库创建好了 echo hell ...