题解 ZOJ3203 Light Bulb
也就是loj上的#10016灯泡了...
先上原图:
因为长度肯定是个开口向下的二次函数,所以先是确定用三分来找位置,然后想办法求出当前阴影长度
看到这条斜线,就想到了一次函数,所以就建了一个系,没想到还真解出来了。
首先设灯泡位置为(H,0),再设它与人头之间连接的线段所在直线为y=kx+b
所以b=H(在灯泡处入x=0代可以解出来),k=(h-b)/x=(h-H)/x(这个不用解释吧)
所以这条直线(也就是光线)与地面相交于y=0时
即x1=-b/k。
因为b,k已知,所以肯定求得出来
然后判断是否大于D
如果小于D,直接返回x1-x
如果大于D,那么在墙上的一截就是当x=D时,y的值,即y=k*D+b
这样就可以了
代码如下:
#include<cstdio> double b,h,d,l,r; inline double max(double a,double b){
return a>b?a:b;
} inline double f(double x){
double k=(h-b)/x;//求k
double x1=-b/k;//求x1if(x1<=d)return x1-x;//判断
return d-x+k*d+b;
} int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%lf%lf%lf",&b,&h,&d);//干脆把b当H输入
l=,r=d;
while(l+1e-<r){//我这样写midl与midr只是图方便,不是有什么特殊的方法
double midl=(l+r)/;
double midr=(midl+r)/;
if(f(midl)<=f(midr))l=midl;
else r=midr;
}
printf("%.3lf\n",f(l));
}
return ;
}
完结撒花!!!✿✿ヽ(°▽°)ノ✿
题解 ZOJ3203 Light Bulb的更多相关文章
- Light Bulb(三分)
ZOJ Problem Set - 3203 Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildl ...
- 三分 --- ZOJ 3203 Light Bulb
Light Bulb Problem's Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 Mean: ...
- 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 (三分+计算几何)
B - Light Bulb Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- 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 ...
随机推荐
- PowerPC汇编指令集
PowerPC 体系结构规范(PowerPC Architecture Specification)公布于 1993 年,它是一个 64位规范 ( 也包括 32 位子集 ).差点儿全部常规可用的 Po ...
- PL/SQL Developer自己主动补全SQL语句
快捷输入SQL语句,比如输入s,按下空格,自己主动替换成SELECT;再比如,输入se,按下空格, 自己主动替换成SELECT * FROM,很方便,节省了大量的时间去编写反复的SQL语句. 设置方法 ...
- Intent 使用方法全面总结
调用拨号程序 // 给移动客服10086拨打电话 Uri uri = Uri.parse("tel:10086"); Intent intent = new Intent(Inte ...
- android制作闪动的红心
先上一张效果图吧: 说说这个东西的来源吧.今天突然想到笛卡尔心形图,想去看看能不能画个心出来,可是看到一篇不错的文章,那篇文章罗列了非常多关于心形的函数方程,这可把我高兴坏了,于是我选取了一个比較好看 ...
- Android 四大组件学习之ContentProvider二
上节学习了什么是ContentProvider.以及ContentProvider的作用.以及什么是URL.本节就对上节学习的知识做一个实践,也就是定义自己的ContentProvider 好.实践是 ...
- mysql 10060远程不能访问
1.网络不通. 检查能不能ping通. 2.防火墙设置. 防火墙是否放过MySQL的进程,是否屏蔽了mysql的3306端口. 3.mysql的账户设置. mysql账户是否不允许远程连接.如果无法连 ...
- sql server drop login failed
https://stackoverflow.com/questions/37275/sql-query-for-logins https://www.mssqltips.com/sqlserverti ...
- Dark roads--hdoj
Dark roads Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Su ...
- js 数组包含
function(arr,element){ return new RegExp('(^|,)'+element.toString()+'(,|$)').test(arr.toString()); }
- etcd创建集群并增加节点
下载安装 从这下载https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.tar.gz tar ...