练习二 1005 Turn the corner
2016-04-23 20:53
274 查看
[align=left]题目:[/align]
[align=left]Problem Description[/align]
Mr. West bought a new car! So he is travelling around the city.<br><br>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.<br><br>Can Mr. West go across the corner?<br><img src=../../../data/images/2438-1.jpg><br>
[align=left]Input[/align]
Every line has four real numbers, x, y, l and w.<br>Proceed to the end of file.<br>
[align=left]Output[/align]
If he can go across the corner, print "yes". Print "no" otherwise.<br>
[align=left]Sample Input[/align]
10 6 13.5 4<br>10 6 14.5 4<br>
[align=left]Sample Output[/align]
yes<br>no<br>
题意:一辆长为l,宽为w的车要从宽为x的公路拐到宽为y的公路,问能不能成功。解题思路:画出符合题意的图,并根据图写出车辆能拐到y公路的最大宽度的方程h=f(a),由题意可知h为凸函数,所以我们只要求出h在(0.pi/2)的最值即可(三分法求出),且h=-(xtan(a)+lsin(a)+w/cos(a)),若h<y,则车可以通过,反之不可。感想:三分+几何计算问题。只要这个题的图画出来了一切的问题都会迎刃而解,不过虽然画出了图但是计算公式却写错了好几次,改了好几次才通过。代码:
[align=left]Problem Description[/align]
Mr. West bought a new car! So he is travelling around the city.<br><br>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.<br><br>Can Mr. West go across the corner?<br><img src=../../../data/images/2438-1.jpg><br>
[align=left]Input[/align]
Every line has four real numbers, x, y, l and w.<br>Proceed to the end of file.<br>
[align=left]Output[/align]
If he can go across the corner, print "yes". Print "no" otherwise.<br>
[align=left]Sample Input[/align]
10 6 13.5 4<br>10 6 14.5 4<br>
[align=left]Sample Output[/align]
yes<br>no<br>
题意:一辆长为l,宽为w的车要从宽为x的公路拐到宽为y的公路,问能不能成功。解题思路:画出符合题意的图,并根据图写出车辆能拐到y公路的最大宽度的方程h=f(a),由题意可知h为凸函数,所以我们只要求出h在(0.pi/2)的最值即可(三分法求出),且h=-(xtan(a)+lsin(a)+w/cos(a)),若h<y,则车可以通过,反之不可。感想:三分+几何计算问题。只要这个题的图画出来了一切的问题都会迎刃而解,不过虽然画出了图但是计算公式却写错了好几次,改了好几次才通过。代码:
#include<iostream> #include<iomanip> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; const double PI=acos(-1.0); double x,y,l,w; double fun(double a) { return -((x-l*sin(a)-w/cos(a))/tan(a)); } double find(double l, double r) { double mid,midmid; while(r-l>1e-6) { mid=(l+r)/2; midmid=(r+mid)/2; if(fun(mid)>fun(midmid)) r=midmid; else l=mid; } return l; } int main() { while(cin>>x>>y>>l>>w) { if(x<w||y<w||fun(find(0,PI/2))>y) cout<<"no"<<endl; else cout<<"yes"<<endl; } return 0; }
相关文章推荐
- imx280学习之Uboot移植
- POJ 3061 Subsequence(尺取法)
- [C++]pseudo-random numbers(random库)
- Fragment的使用详解
- 冲刺第五天
- MySQL基础2
- Oracle11g 启动报错ORA-00845: MEMORY_TARGET not supported on this system报错解决
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- Android Alarm 的设置
- 冲刺第四天
- I/O Completion Ports
- 学习笔记(六)探究碎片 Fragment 之二
- (2.2.8.1)关于Android Studio里的Gradle,你所需要知道的都在这里了
- Camtasia Studio实现画中画视频课件制作方案
- Android Volley+OkHttp3+Gson 开源库的封装
- IOS设计模式浅析之适配器模式(Adapter)
- 百度2016研发工程师(感谢博主)
- Photo&Vedio的拍摄
- 第8周学习进度情况
- Android——C语言、JNI与低层调用