注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

东月之神

在单纯的观念里面,生命就容易变得比较深刻!

 
 
 

日志

 
 
关于我

别驻足,梦想要不停追逐,别认输,熬过黑暗才有日出,要记住,成功就在下一步,路很苦,汗水是最美的书!

网易考拉推荐

三分法求极值问题  

2010-04-03 13:41:25|  分类: ACM |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
 

zoj   3203   Light Bulb

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
以前做这题还用高数的知识的。不过贡献了好多次WA,近几天经过朋友的指导,才知道有个三分可以搞定。。菜的不行了啊!!
下面是代码:
#include <stdio.h>
int main()
{
 int t;
 scanf("%d", &t);
 while(t--)
 {
  double h, H, D;
  scanf("%lf%lf%lf", &H, &h, &D);
  double left = 0, right = D * h / H;
   int size = 100;
  double mid, midmid, ans1, ans2;
  while(size--)
  {
    mid = (left + right) / 2;
    midmid = (mid + right) / 2;
      ans1 = ((h*D-H*mid)/(H-h)*H)/((h*D-H*mid)/(H-h)+D)+mid;
     ans2 = ((h*D-H*midmid)/(H-h)*H)/((h*D-H*midmid)/(H-h)+D)+midmid;
    if(ans1 > ans2) right = midmid;
      else left = mid;
  }
  printf("%.3lf\n", ans1);
 }
return 0;
}
 
 
hdu  2438  turn the corner

Turn the corner

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 404    Accepted Submission(s): 103


Problem Description
Mr. West bought a new car! So he is travelling around the city.

One day he comes to a vertical corner. The street he is currently in has a width x, the street he wants to turn to has a width y. The car has a length l and a width d.

Can Mr. West go across the corner?
三分法求极值问题 - 东月之神 - 东月之神
 

Input
Every line has four real numbers, x, y, l and w.
Proceed to the end of file.
 

Output
If he can go across the corner, print "yes". Print "no" otherwise.
 

Sample Input
10 6 13.5 4 10 6 14.5 4
 

Sample Output
yes no
 
#include <cstdio>
#include <cmath>
const double pi = 3.1415926535;
int main()
{
 double x, y, l, w;
 while(scanf("%lf%lf%lf%lf", &x, &y, &l, &w) != EOF)
 {
  int size = 100;
  double left = 0, right = pi / 2;
  double mid = 0, midmid = 0, ans1, ans2;
  if(x < w || y < w){printf("no\n"); continue;} 
  while(size--)
  {
   mid = (left+right) / 2;
   midmid = (mid+right) / 2;
   ans1 = (x-l*sin(mid)-w/cos(mid)) / tan(mid);
   ans2 = (x-l*sin(midmid)-w/cos(midmid)) / tan(midmid);
   if(ans1 < ans2) right = midmid;
   else left = mid;
  }
  if(fabs(ans1) > y) printf("no\n");
  else printf("yes\n");
 }
return 0;
}
  评论这张
 
阅读(760)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017