博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ_ACM_Turn the corner
阅读量:5748 次
发布时间:2019-06-18

本文共 2228 字,大约阅读时间需要 7 分钟。

 

Problem Description
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 410 6 14.5 4
 
Sample Output
yesno
 

 Idea

To begin with, if d is smaller than x or y, then it's sure that the car couldn't pass the conner. Besides, we can considerate the l, which can be composed by a.

l = [(x / sin(a) + y / cos(a)) * cos(a) - d / sin(a)] / cos(a)

simplify the equality, we can get

l = x / sin(a) + y / cos(a) - d / sin (a) / cos(a)

then I can get l' and l'', but I can't find the any regulation about those.

what's a pity!

so I just use trichotomy to get similarity of l. I know it's luck.

 

Code

1 #include 
2 #include
3 double x, y, l, d; 4 double f(double a) 5 { 6 return x / sin(a) + y / cos(a) - d / sin(a) / cos(a); 7 } 8 void main() 9 {10 double low, high, mid1, mid2;11 int i;12 while (scanf("%lf %lf %lf %lf", &x, &y, &l, &d) != EOF)13 {14 //there are two situation15 if (d >= x || d >= y)16 {17 puts("no");18 }19 else20 {21 high = acos(-1.0) / 2;22 low = 0;23 while (fabs(high - low) >= 1e-7)24 {25 mid1 = (high + low) / 2;26 mid2 = (mid1 + high) / 2;27 //printf("%f, %f, %f, %f\n",28 // mid1, mid2, f(mid1), f(mid2));29 if (f(mid1) < f(mid2))30 high = mid2;31 else32 low = mid1;33 }34 //printf("high = %f, low = %f\n", high, low);35 if (l < f(low))36 puts("yes");37 else38 puts("no");39 }40 }41 }

 

 

Key Points

Pay more attention to the algorithm.

 

转载于:https://www.cnblogs.com/chuanlong/archive/2013/03/15/2961785.html

你可能感兴趣的文章
雷林鹏分享:codeigniter框架文件上传处理
查看>>
数据库连接
查看>>
Android开发学习——自定义View
查看>>
JQ使用Append添加html文本后再删除该html文本
查看>>
B/S与C/S结构的区别
查看>>
MathType中常见的两种符号的运用
查看>>
自动填充功能关闭解决表单input框屎黄色问题
查看>>
python_控制台输出带颜色的文字方法
查看>>
Java线程Thread的状态解析以及状态转换分析 多线程中篇(七)
查看>>
[十二]JavaIO之BufferedInputStream BufferedOutputStream
查看>>
java泛型中特殊符号的含义
查看>>
一秒 解决 ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql 问题
查看>>
linuxan安装redis出现Newer version of jemalloc required错误
查看>>
在centos7下用http搭建配置svn服务
查看>>
PHP APP端支付宝支付
查看>>
TCP长连接的一些事儿
查看>>
Android组件化最佳实践 ARetrofit原理
查看>>
舍弃浮躁, 50条重要的C++学习建议
查看>>
Hibernate懒加载/延迟加载机制总结
查看>>
fail2ban安装与使用
查看>>