ZOJ 3203 Light Bulb (三分)

本文介绍了一种利用三角形相似原理计算最大阴影长度的方法,并通过三分法找到最佳解。给出具体实现代码。

 

 

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, thinking of how to earn more money. One day, he found that the length of his shadow was changing from time to time while walking between the light bulb and the wall of his house. A sudden thought ran through his mind and he wanted to know the maximum length of his shadow.

Input

The first line of the input contains an integer T (T <= 100), indicating the number of cases.

Each test case contains three real numbers H, h and D in one line. H is the height of the light bulb while h is the height of mildleopard. D is distance between the light bulb and the wall. All numbers are in range from 10-2 to 103, both inclusive, and H - h >= 10-2.

Output

For each test case, output the maximum length of mildleopard's shadow in one line, accurate up to three decimal places..

Sample Input

 

3
2 1 0.5
2 0.5 3
4 3 4

 

Sample Output

 

1.000
0.750
4.000

 

这题的关键是写出一个等式,这里用三角形的相似来得出一个等式 我们假设地下的影子的长度为 X ,这里有两个相似的直角三角形,他们的直角边的比值是   (H-L) / D = (h-L)/ x  等式化简有   X = D*(h-L) / (H-L)    ,  影子的全部长度为地上的长度加上墙上的长度L  ,在上式两边同时加上 L  有   Y = X + L =  D*(h-L) / (H-L) + L   这里的等式的未知数就是L ,L (墙上的长度)的范围肯定是 0 到 h  ,那么,通过三分法求出L的值,即可得出答案;代码如下:

 

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<time.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<list>
#include<queue>
#include<map>
#define E exp(1)
#define PI acos(-1)
#define mod (ll)(1e9+9)
#define INF 0x3f3f3f3f;
#define MAX 40000
//#define _CRT_SECURE_NO_WARNINGS
//#define LOCAL
using namespace std;

typedef long long ll;
typedef long double lb;



int main(void)
{
#ifdef LOCAL
	freopen("data.in.txt", "r", stdin);
	freopen("data.out.txt", "w", stdout);
#endif
	int t;
	double H, h, D;
	while (scanf("%d", &t) != EOF) {
		for (int i = 1; i <= t; ++i) {
			scanf("%lf%lf%lf", &H, &h, &D);
			double le, ri, lmid, rmid, tmp_1, tmp_2;
			le = 0, ri = h;
			while (fabs(ri - le) > 1e-8) {
				lmid = (ri + le) / 2;
				rmid = (lmid + ri) / 2;
				tmp_1 = D*(h - lmid) / (H - lmid) + lmid;
				tmp_2 = D * (h - rmid) / (H - rmid) + rmid;
				if (tmp_1 > tmp_2) ri = rmid;
				else le = lmid;
			}
			double x = (ri + le) / 2;
			double res = D * (h - x) / (H - x) + x;
			double tmp = max(D * h / H, h);
			res = max(tmp, res);
			printf("%.3f\n", res);
		}
	}
	//	end = clock();
	//	cout << "using tmie:" << (double)(end - start) / CLOCKS_PER_SEC * (1000) << "ms" << endl;

	//system("pause");
	return 0;
}

 

 

 

光伏储能虚拟同步发电机VSG并网仿真模型(Similink仿真实现)内容概要:本文档介绍了光伏储能虚拟同步发电机(VSG)并网仿真模型的Simulink实现方法,重点在于通过建立光伏储能系统与虚拟同步发电机相结合的仿真模型,模拟其在并网过程中的动态响应与控制特性。该模型借鉴了同步发电机的惯性和阻尼特性,提升了新能源并网系统的频率和电压支撑能力,增强了系统的稳定性与可控性。文档还提及相关电力系统仿真技术的应用,包括逆变器控制、储能配置、并网稳定性分析等,并提供了完整的Simulink仿真文件及技术支持资源链接,便于科研人员复现与二次开发。; 适合人群:电气工程、自动化、能源系统等相关专业的研究生、科研人员及从事新能源并网技术开发的工程师。; 使用场景及目标:①用于研究光伏储能系统在弱电网条件下的并网稳定性问题;②掌握虚拟同步发电机(VSG)控制策略的设计与仿真方法;③支持高水平论文(如EI/SCI)的模型复现与创新研究;④为微电网、智能电网中的分布式能源接入提供技术参考。; 阅读建议:建议结合提供的Simulink模型文件与文档说明逐步操作,重点关注VSG控制模块的参数设置与动态响应分析,同时可延伸学习文中提及的MPPT、储能管理、谐波分析等相关技术,以提升综合仿真能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值