acm课程练习2--1005
2016-04-24 19:08
134 查看
题目描述
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
大意
求长为l,宽为w的汽车能否通过前后道路宽度依次为x与y的90度直角弯道思考
很明显,这是一道数学题,公式的推导过程很是麻烦,我也是参考了题解才推导出正确的公式,主要参考了这篇博客。这是一个凸性函数,因此我用了三分搜素法来做
AC代码
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
double pi = acos(-1.0);
double x,y,l,w,s,h;
double cal(double a)
{
s = l*cos(a)+w*sin(a)-x;
h = s*tan(a)+w*cos(a);
return h;
}
int main()
{
double left,right,mid,midmid;
while(scanf("%lf%lf%lf%lf",&x,&y,&l,&w)!=EOF)
{
left = 0.0;
right = pi/2;
while(fabs(right-left)>1e-8)
{
mid = (left+right)/2;
midmid = (mid+right)/2;
if(cal(mid)>=cal(midmid))right = midmid;
else left = mid;
}
if(cal(mid)<=y)printf("yes\n");
else printf("no\n");
}
return 0;
}//三分法程序
[/code]
做这道题好像做高中的数学题(不过好难)。。。。
来自为知笔记(Wiz)
相关文章推荐
- android Binder 学习
- AsyncTask解析(上)——原理分析与超简单demo实现
- wso2esb 4.9.0中无法启动Axis2Server的解决办法
- 【Python】__all__ 暴露接口
- 判断链表是否带环,若带环,找到环的入口点
- 利用后缀数组构造后缀树
- LoaderManager使用详解(四)---实例:AppListLoader
- 一周乱弹(1,绝对路径中的 / 代表什么 2,jsp include标签 3,java 获取ip地址问题,4,springMVC @RequestMapping 传递多个参数5,jQuery模糊搜索)
- response.sendRedirect()与request.getRequestDispatcher().forward()区别
- R 数据读入
- Android常用抓包工具之TcpDump
- 5天揭秘js高级技术-第二天
- 数素数,PAT,1013
- sdau-2 1013 1014
- Some Basic Concepts in Image Steganography
- 222. Count Complete Tree Nodes
- Animation and Transitions in Qt Quick | Qt Quick 5
- Hadoop MapReduce多表关联程序
- 项目完成中的心得
- git使用(1) --git本地基础操作