ZOJ 3203

很简单的一题,注意墙上的影子是放大就行。用三分。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

double H,h,D;

double cal(double x){
	return x+(h-x/D*H)*D/(D-x);
}

int main(){
	double ans; int T;
	scanf("%d",&T);
	while(T--){
		scanf("%lf%lf%lf",&H,&h,&D);
		ans=h/H*D;
		double l=0,r=ans;
		double m,mm;
		while(l+(1e-8)<r){
			m=l+(r-l)/3;
			mm=r-(r-l)/3;
			if(cal(m)>cal(mm))
			r=mm;
			else l=m;
		}
		ans=max(ans,cal(l));
		printf("%.3lf\n",ans);
	}
	return 0;
}

  

时间: 2024-10-19 12:09:34

ZOJ 3203的相关文章

ZOJ 3203: Light Bulb

ZOJ 3203: Light Bulb 1 ///@author Sycamore, ZJNU 2 ///@date 2017-02-09 3 #include<algorithm> 4 #include<iostream> 5 #include<iomanip> 6 #define eps 1e-10 7 using namespace std; 8 double H, h, L, D; 9 double getL(double a) 10 { 11 return

ZOJ 3203 Light Bulb (三分+计算几何)

题目地址:ZOJ 3203 第一发三分.三分的原理还是挺简单的. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h&g

zoj 3203 Light Bulb,三分基础题

Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodio

ZOJ 3203 Light Bulb 三分

最简单的三分题,期末考完先做一道练练手 就是这么一个图,告诉你H h D,问你L最长是多少,假设人到灯的距离是X,那么容易得到 L = H-D/x*(H-h)+D-x,求个导很容易发现是一个关于x 的凸性函数,就可以三分啦 要注意的是三分的时候的精度eps,这题要求得是1e-9才能A,1e-8都WA,真是囧 #include <cstdio> #include <sstream> #include <fstream> #include <cstring> #

zoj 3203 Light Bulb(公式推导|三分法)(简单)

Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodio

zoj 3203 Light Bulb,三分之二的基本问题

Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodio

ZOJ 3203 灯泡

题面 相比 wildleopard 的家,他的弟弟 mildleopard 比较穷.他的房子是狭窄的而且在他的房间里面仅有一个灯泡.每天晚上,他徘徊在自己狭小的房子里,思考如何赚更多的钱.有一天,他发现他的影子的长度随着他在灯泡和墙壁之间走到时发生着变化.一个突然的想法出现在脑海里,他想知道他的影子的最大长度.  思路 首先,分治肯定是能够想到的,但是是二分还是三分呢,我们只需要思考一下就能知道,我们设地上影长为L1,墙上为L2,人走近时L1增加,L2减小,走远时L1减小,L2增加--这是个二次

[清华集训2015]灯泡(浙江大学ZOJ 3203 Light Bulb)

Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, t

三分算法

三分算法 二分算法解决的是具有单调性的问题. 三分算法解决的是抛物线的类型,上凸,下凹. mid=(Left+Right)/2; midmid=(Right+mid)/2; 题目类型有: HDU :3400  2298  4454  2438  3756 POJ:  3301   3737 ZOJ: 3203