acm课程练习2--1005
题目描述
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;}//三分法程序
做这道题好像做高中的数学题(不过好难)。。。。
acm课程练习2--1005的更多相关文章
- ACM课程学习总结
ACM课程学习总结报告 通过一个学期的ACM课程的学习,我学习了到了许多算法方面的知识,感受到了算法知识的精彩与博大,以及算法在解决问题时的巨大作用.此篇ACM课程学习总结报告将从以下方面展开: 学习 ...
- ACM课程总结
当我还是一个被P哥哥忽悠来的无知少年时,以为编程只有C语言那么点东西,半个学期学完C语言的我以为天下无敌了,谁知自从有了杭电练习题之后,才发现自己简直就是渣渣--咳咳进入正题: STL篇: 成长为一名 ...
- 华东交通大学2016年ACM“双基”程序设计竞赛 1005
Problem Description 最近侯ry感觉自己在数学方面的造诣不忍直视:他发现他的学习速率呈一个指数函数递增,疯狂的陷入学习的泥潭,无法自拔:他的队友发现了他的学习速率y=e^(b*lna ...
- acm课程练习2--1013(同1014)
题目描述 There is a strange lift.The lift can stop can at every floor as you want, and there is a number ...
- acm课程练习2--1003
题目描述 My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numb ...
- acm课程练习2--1002
题目描述 Now, here is a fuction: F(x) = 6 * x^7+8x^6+7x^3+5x^2-yx (0 <= x <=100)Can you find the ...
- acm课程练习2--1001
题目描述 Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and ...
- 华东交通大学2015年ACM“双基”程序设计竞赛1005
Problem E Time Limit : 3000/2000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- 华东交通大学2017年ACM“双基”程序设计竞赛 1005
Problem Description 假设你有一个矩阵,有这样的运算A^(n+1) = A^(n)*A (*代表矩阵乘法)现在已知一个n*n矩阵A,S = A+A^2+A^3+...+A^k,输出S ...
随机推荐
- SharePoint 2013 配置InfoPath 列表表单
转载来源:http://www.cnblogs.com/jianyus/p/3470113.html SharePoint列表,都是通过表单展示,有时候不太符合要求,这时候,我们可以通过定制表单,来是 ...
- runtime官方文档
OC是一种面向对象的动态语言,作为初学者可能大多数人对面向对象这个概念理解的比较深,而对OC是动态语言这一特性了解的比较少.那么什么是动态语言?动态语言就是在运行时来执行静态语言的编译链接的工作.这就 ...
- HttpServletResponse应用----生成验证码
1.1生成随机图片用作验证码 生成图片主要用到BufferedImage类 package gacl.response.study;import java.awt.Color;import java. ...
- 查询全国的省市信息<option>拼接
//修改页面获取省市信息 function getProvinceUSER_AREA1(){ $.ajax({ type:'post', url:'<%=path%>/user/findU ...
- 消除警告"property access result unused - getters should not be used for side effects"
我写了如下一段代码: - (void)btnClicked:(UIButton *)button { switch (button.tag) { : self.initShare; break; de ...
- mysql多表链接查询
select area from areas where cityid=(select cityid from cities where city like '杭州%') and id!=(selec ...
- 如何通过Maven的Tomcat插件运行Web工程
去tomcat官网http://tomcat.apache.org/,左侧栏Apache Tomcat下的Maven Plugin,点进去选择最新版本Version 2.2 通过介绍可知,使用tomc ...
- spring中JdbcTemplate的使用
一.首先JdbcTemplate有一个DataSource类型的属性,所以需要在spring的配置文件中为JdbcTemplate的实例配置dataSource属性: <!-- 导入资源文件 - ...
- postgresql 修改属性
up vote2down votefavorite From this article, I tried to update or delete property of a JSONB column: ...
- IP子网掩码划分及设置
IP子网掩码划分及设置 定长子网掩码: 一.子网掩码的计算 TCP/IP网间网技术产生于大型主流机环境中,它能发展到今天的规模是当初的设计者们始料未及的.网间网规模的迅速扩展对IP地址模式的威胁并不是 ...