ZOJ 3203 Light Bulb【数学推导&三分】
来源:互联网 发布:英语作文人工智能 编辑:程序博客网 时间:2024/05/29 17:17
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
32 1 0.52 0.5 34 3 4
Sample Output
1.0000.7504.000
思路一:数学推导(求函数极值)
http://blog.csdn.net/freezhanacmore/article/details/9887115
#include<cstdio>#include<math.h>#include<cstring>#include<climits>#include<string>#include<queue>#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<climits>#include<string>#include<queue>#include<stack>#include<set>#include<map>#include<algorithm>using namespace std;#define rep(i,j,k)for(i=j;i<k;i++)#define per(i,j,k)for(i=j;i>k;i--)#define MS(x,y)memset(x,y,sizeof(x))#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define ll long long#define abs(x) (x>0?x:-x)const int INF=0x7ffffff;const ll MAX=1e18;int i,j,k,n,m;double H,h,D;int main(){ int T; scanf("%d",&T); while(T--){ scanf("%lf%lf%lf",&H,&h,&D); double x0=sqrt((H-h)*D); double left=((H-h)*D)/H,right=D; double x; if(left<=x0&&right>=x0)x=x0; else if(right<x0)x=right; else x=left; printf("%.3lf\n",D+H-(x+(H-h)*D/x)); } return 0;}
思路二:三分
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
32 1 0.52 0.5 34 3 4
Sample Output
1.0000.7504.000
- ZOJ 3203 Light Bulb【数学推导&三分】
- zoj 3203 Light Bulb(三分)
- zoj 3203 - Light Bulb (三分)
- zoj 3203 Light Bulb 三分
- ZOJ 3203 Light Bulb--三分
- 三分 --- ZOJ 3203 Light Bulb
- ZOJ 3203 Light Bulb 三分
- ZOJ 3203Light Bulb(数学)
- ZOJ 3203 Light Bulb 三分查找
- zoj 3203 Light Bulb(三分)
- ZOJ 3203 Light Bulb (三分算法)
- ZOJ 3203 Light Bulb(三分)
- zoj 3203 Light Bulb,三分基础题
- ZOJ 3203 Light Bulb 三分\推公式
- zoj 3203 Light Bulb 三分入门
- zoj 3203 Light Bulb (三分)
- Zoj 3203 Light Bulb (三分查找)
- ZOJ 3203 Light Bulb (三分+计算几何)
- 虚幻UE4常见问题最全集合
- caffe源码深入学习2:blob.hpp+blob.cpp
- CCF之矩阵(java)
- 第二章photoshop基础操作
- cs231n 课程作业 Assignment 1
- ZOJ 3203 Light Bulb【数学推导&三分】
- 初学者(-)eclipse的使用
- Mysql 8.0 新增特性
- Cookie的相关资料
- 一个值得学习的资料
- 历届试题 数字游戏
- 左偏树-总结
- centos 使用暗黑主题
- #“Machine Learning”(Andrew Ng)#Week 4_1:Neural Networks(神经网络)