ZOJ 3203 Light Bulb - 求导求最大值
如果L全在地面上:
输出 h * D / H
如果L全在墙上:
输出 h
否则:
(D - X ) / X = Y / (H - h)
L = D - X + h - Y
然后对L求导即可
1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #include <algorithm> 5 using namespace std; 6 7 int main(){ 8 double H,h,D,x,y,x0; 9 int t; 10 scanf("%d",&t); 11 while(t--){ 12 scanf("%lf%lf%lf",&H,&h,&D); 13 x0 = D - h * D / H; 14 x = sqrt( D * (H - h) ); 15 y = (D - x) * (H - h) / x; 16 if(x >= D) printf("%.3lf\n",h); 17 else if(x < x0) printf("%.3lf\n",h * D / H); 18 else printf("%.3lf\n",h - y + D - x); 19 } 20 return 0; 21 }
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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(三):用.NET IoT库
· 【非技术】说说2024年我都干了些啥
2014-04-02 ZOJ 3609 求逆元