ZOJ Problem Set - 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, 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

题解:找出函数,两种方法,一种求导直接求,另一种是三分;

法一:
 #include<stdio.h>
#include<math.h>
int main(){
int T;
double H,h,D;
//公式:D-x+H-(H-h)*D/x;
//求导:-1+(H-h)*D/(x*x)
//导数等于0,求得极值x=sqrt((H-h)*D)
//影子在地面最长时x=(H-h)*D/H;
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf",&H,&h,&D);
double jz=sqrt((H-h)*D);
double ans;
if(jz<=(H-h)*D/H)ans=D-(H-h)*D/H;
else if(jz>=D)ans=h;
else ans=D-jz+H-(H-h)*D/jz;
printf("%.3lf\n",ans);
}
return ;
}

三分:

 #include<stdio.h>
#include<math.h>
double H,h,D;
double getl(double x){
return D-x+H-(H-h)*D/x;
}
void sanfen(){
double l=(H-h)*D/H,m,mm,r=D;//l从地面最长开始
while(r-l>1e-){
m=(l+r)/;
mm=(m+r)/;
if(getl(m)>=getl(mm))r=mm;
else l=m;
}
printf("%.3lf\n",getl(l));
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf",&H,&h,&D);
sanfen();
}
return ;
}

Light Bulb(三分)的更多相关文章

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

    B - Light Bulb Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  2. ZOJ - 3203 Light Bulb(三分)

    题意:灯离地面的高度为$H$,人的身高为$h$,灯离墙的距离为$D$,人站在不同位置,影子的长度不一样,求出影子的最长长度. 思路:设人离灯的距离为$x$,当人走到距离灯长度为$L$时,人在墙上的影子 ...

  3. 三分 --- ZOJ 3203 Light Bulb

    Light Bulb Problem's Link:   http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 Mean: ...

  4. ZOJ 3203 Light Bulb (三分查找)

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

  5. A. Light Bulb

    A. Light Bulb Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 32768KB   64-bit integer IO f ...

  6. ZOJ 3203 Light Bulb - 求导求最大值

    如果L全在地面上: 输出 h * D / H 如果L全在墙上: 输出 h 否则: (D - X ) / X = Y / (H - h) L = D - X + h - Y 然后对L求导即可 #incl ...

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

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

  8. ZOJ 3203 Light Bulb

    Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow a ...

  9. ZOJ 3203 Light Bulb(数学对勾函数)

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

随机推荐

  1. activiti框架 数据库设计说明

    1.结构设计 1.1.    逻辑结构设计 Activiti使用到的表都是ACT_开头的. ACT_RE_*: ’RE’表示repository(存储),RepositoryService接口所操作的 ...

  2. linux使用工具记录

    linux工具查询手册: http://linuxtools-rst.readthedocs.io/zh_CN/latest/index.html

  3. javascript - 工作笔记 (事件绑定)

    背景: 目前所做的项目,只能使用的是原生的javascript.对于javascript的事件绑定想必大家都懂得语法: 1,在标签中使用属性调用方法:<div onclick="AAA ...

  4. 如何在程序中动态设置墙纸(使用IActiveDesktop接口)

    大家都知道设置WINDOWS桌面墙纸的WIN32 API是SystemParametersInfo, 使用SPI_SETDESKWALLPAPER参数便能设置墙纸: ::SystemParameter ...

  5. javascript函数的基础功能

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  6. android 传感器使用 Compass指南针的实现功能

    以下是指南针通过方向传感器而旋转实现. CompassDemo.java: package com.example.activity; import android.app.Activity; imp ...

  7. ASP.NET MVC4 ASP.NET Web API路由规则

    using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Web.Ht ...

  8. 2013年 ACM 有为杯 Problem I (DAG)

    有为杯  Problem I DAG  有向无环图 A direct acylic graph(DAG),is a directed graph with no directed cycles . T ...

  9. 手机root初体验

    看到别人写的一些自己想知道的东西,顿时感到很有兴趣也很强大,固然做一个牛人有很多小粉丝是无比崇高的,可去往牛人的路上也不能少了自己~加油! 一 我来解释一下什么是ROOT以及原理 是不是要ROOT,是 ...

  10. MongoDB入门学习(一)—— 安装和启动

    最近由于工作需要,开始学习MongoDB数据库了.第一篇博文就从这里开始吧,以此记录下学习中的点点滴滴,为自己加油呢! (一) MongoDB简介 网上搜搜了一下:(来源:http://www.run ...