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 ...
随机推荐
- ESFramework 4.0 性能测试
本实验用于测试ESFramework服务端引擎的性能,测试程序使用ESFramework 4.0版本. 一.准备工作 测试的机器总共有3台,都是普通的PC,一台作为服务器,两台作为客户端. 作为服务器 ...
- LeetCode OJ 162. Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- Matlab - 矩阵基本操作
1. 矩阵的输入 右值是用方括号表示: , 逗号或空格分隔元素 ; 分号分隔行 >> A = [-, ; , ] A = - 2. 矩阵的加减 >> C = A + B ...
- html5 读写sqlite数据库
var db = openDatabase('MyData','','My Database',102400); //首先它创建一个数据库表,里面有3个字段 db.transaction(functi ...
- java的静态方法的使用
静态的方法和属性,你可以这么理解,就是所有对象公用的,比如一个属性是这样定义的: private static String name; 那么他的意思就是说,因为他是静态的,我所有的对象的name属性 ...
- kvstore之mongodb为存储介质
配置config(连接mongo) mongo define('KVSTORE_STORAGE', 'base_kvstore_mongodb'); define('MONGODB_SERVER_CO ...
- 运行CImg库笔记
1. 在程序代码中加入 #include "CImg.h" using namespace cimg_library; 2. (1)Mac下 出现错误“无X11/Xlib.h”,: ...
- 拦截asp.net输出流做处理, 拦截HTML文本(asp.net webForm版)
对已经生成了HTML的页面做一些输出到客户端之前的处理 方法的原理是:把Response的输出重定向到自定义的容器内,也就是我们的StringBuilder对象里,在HTML所有的向页面输出都变 成了 ...
- prestashop 基本设置
不跳转 要先改这个UPDATE`ps_shop_url`SET`domain_ssl`= replace(`domain_ssl` ,'us2.try.net','www.gelchaussures. ...
- <转>如何高效快速看懂Android源码
原网址:http://jingyan.baidu.com/article/574c5219ca78ed6c8d9dc12a.html 在Android系统上工作了一段时间,经常会遇到题目中的问题,下面 ...