Turn the corner(三分)
来源:互联网 发布:淘宝限时折扣 编辑:程序博客网 时间:2024/06/14 03:38
题目链接:点击打开链接
题目大意:求能否拐弯;
思路:可以当一条边的宽度已知,求另一条路的最短宽度;
(在其他的人的博客中找的图,画着太麻烦了)
这样可以求出,任意角度下,所需要的y最小值;
让h与y做对比,找h的最小值时,要用到三分来查找;
代码:
#include<stdio.h>#include<string.h>#include<math.h>#define pi asin(1.0)double x,y,l,w;double cal(double a)//在不同角度下,求出的h值;{ double s=l*cos(a)+w*sin(a)-x; double h=s*tan(a)+w*cos(a); return h;}int main(){ while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&w)) { double left=0.0,right=pi; while(fabs(left-right)>1e-8) { double la=(left*2.0+right)/3.0; double lb=(left+2.0*right)/3.0; if(cal(la)>cal(lb))//不断逼近最小值; right=lb; else left=la; } if(cal(left)<=y) printf("yes\n"); else printf("no\n"); } return 0;}
第一次使用三分,刚开始觉得二分有什么区别,后来发现,三分是用来求最值的(处理曲线,例如二次方程一类的),而二分是用来查找一个数的(例如一条直线上的一个数)。
0 0
- Turn the corner(三分)
- Turn the corner(三分)
- heru 5081 Turn the corner(三分)
- 13.04.07 Turn the corner (三分)
- hdu 2438Turn the corner(三分)
- HDU 2438 Turn the corner(三分)
- hdu 2438 Turn the corner(三分)
- HDU 2438 Turn the corner(三分)
- (三分)Turn the corner -- HDOJ
- hdu2438 Turn the corner 三分
- Turn the corner(hdu2438三分)
- HDU2438 Turn the corner(三分)
- HDU_P2438 Turn the corner(三分)
- HDOJ 题目2438 Turn the corner(三分搜索)
- hdu 2438 - Turn the corner(三分)
- Turn the corner+hdu+三分搜索
- hdu 2483 Turn the corner(三分)
- HDU 2438 Turn the corner(三分)
- 程序员上班时的各种内心戏...
- Android系统状态栏的信号图标显示流程简介
- 欢迎使用CSDN-markdown编辑器
- 页面浮动示例
- qualcomm 平台的lk启动流程
- Turn the corner(三分)
- 2016版的pyCharm 注册码,有效期一直到2112年
- 再次记录下类的对象调用类内函数出现的问题
- Column count doesn't match value count at row 1
- Git与Github使用之--常用本地命令介绍
- CALLOC函数的应用
- 谈谈对原型链的理解
- dataWithContentsOfURL返回nil
- JNI学习积累之三 ---- 操作JNI函数以及复杂对象传递