二分法 (UVA10668 Expanding Rods)(二分+几何)
转载请注明出处:優YoU http://user.qzone.qq.com/289065406/blog/1301845324
大致题意:
一根两端固定在两面墙上的杆 受热弯曲后变弯曲。求前后两个状态的杆的中点位置的距离
解题思路:
几何和二分的混合体

如图,蓝色为杆弯曲前,长度为L。红色为杆弯曲后,长度为s。h是所求
依题意知 S=(1+n*C)*L
又从图中得到三条关系式;
(1) 角度→弧度公式 θr = 1/2*s
(2) 三角函数公式 sinθ= 1/2*L/r
(3) 勾股定理 r^2 – ( r – h)^2 = (1/2*L)^2
把四条关系式化简可以得到

(1)逆向思维解二元方程组:
要求(1)式的h,唯有先求r;但是由于(2)式是三角函数式,直接求r比较困难
(2)因此要用顺向思维解方程组:
在h的值的范围内枚举h的值,计算出对应的r,判断这个r得到的(2)式的右边与左边的值S的大小关系 ( S= (1+n*C)*L )
很显然的二分查找了。。。。。
那么问题只剩下 h 的范围是多少了
下界自然是0 (不弯曲)关键确定上界。题中提及到
Input data guarantee that no rod expands by more than one half of its original length.
意即输入的数据要保证没有一条杆能够延伸超过其初始长度的一半。就是说 S max = 3/2 L
理论上把上式代入(1)(2)方程组就能求到h的最小上界,但是实际操作很困难
因此这里可以做一个范围扩展,把h的上界扩展到 1/2L ,不难证明这个值必定大于h的最小上界,那么h的范围就为0<=h<1/2L
这样每次利用下界low和上界high就能得到中间值mid,寻找最优的mid使得(2)式左右两边差值在精度范围之内,那么这个mid就是h
精度问题是必须注意的
由于数据都是double,当low无限接近high时, 若二分查找的条件为while(low<high),会很容易陷入死循环,或者在得到要求的精度前就输出了不理想的“最优mid”;
精度的处理方法只需将循环条件变为while(high - low < esp){...} ;其中 esp = 1e-6;
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <iomanip>
using namespace std;
///
#define PI acos(-1.0)
#define INF 0xffffff7
#define esp 1e-6
#define maxn 250000 + 10
typedef long long ll;
///
int a[maxn];
int main()
{
double l, n, c;
while(scanf("%lf%lf%lf", &l, &n, &c) && l >= && n >= && c >= )
{
double s = (1.0 + n * c) * l;
double high = 0.5*l;
double low = 0.0;
while(high - low > esp)
{
double m = (high + low)/2.0;//!!!
double r = (4.0*m*m + l*l)/(8.0*m);
double s2 = 2.0 * r * asin(l / (2.0*r));
if(s < s2) high = m;
else low = m;
}
printf("%.3lf\n", high);
}
return ;
}
二分法 (UVA10668 Expanding Rods)(二分+几何)的更多相关文章
- Expanding Rods(二分POJ1905)
Expanding Rods Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13688 Accepted: 3527 D ...
- POJ 1905 Expanding Rods 二分答案几何
题目:http://poj.org/problem?id=1905 恶心死了,POJ的输出一会要lf,一会要f,而且精度1e-13才过,1e-12都不行,错了一万遍终于对了. #include < ...
- Expanding Rods(二分)
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10287 Accepted: 2615 Description When ...
- poj 1905 Expanding Rods 二分
/** 题解晚上写 **/ #include <iostream> #include <math.h> #include <algorithm> #include ...
- UVA 10668 - Expanding Rods(数学+二分)
UVA 10668 - Expanding Rods 题目链接 题意:给定一个铁棒,如图中加热会变成一段圆弧,长度为L′=(1+nc)l,问这时和原来位置的高度之差 思路:画一下图能够非常easy推出 ...
- D - Expanding Rods POJ - 1905(二分)
D - Expanding Rods POJ - 1905 When a thin rod of length L is heated n degrees, it expands to a new l ...
- POJ 1905:Expanding Rods 求函数的二分
Expanding Rods Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13780 Accepted: 3563 D ...
- POJ 1905 Expanding Rods(二分)
Expanding Rods Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 20224 Accepted: 5412 Descr ...
- poj 1905 Expanding Rods(木杆的膨胀)【数学计算+二分枚举】
...
随机推荐
- Hibernate配置文件——hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuratio ...
- CodeForces 176B Word Cut (计数DP)
Word Cut Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...
- mysql数据库中查询时间
项目中要对数据按时间处理,在数据库中,时间处理的格式如 2014-12-09 06:30:17 时间查询出来如下所示: 现在要查询具体有哪天的数据,应用substring函数,SQL如下: ) as ...
- 嵌入式LINUX入门到实践(二)
这篇中将围绕韦东山LINUX第二部分教程源码,对IIC协议进行程序实现上的分析. /* I2C registers */#define IICCON (*(volatile unsigned ...
- HDU 3265 Posters (线段树+扫描线)(面积并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3265 给你n个中间被挖空了一个矩形的中空矩形,让你求他们的面积并. 其实一个中空矩形可以分成4个小的矩 ...
- HDU/杭电2013多校第三场解题报告
今天悲剧了,各种被虐啊,还是太年轻了 Crime 这道题目给的时间好长,第一次就想到了暴力,结果华丽丽的TLE了. 后来找了一下,发现前24个是1, 2, 6, 12, 72, 72, 864, 17 ...
- shiro安全框架
原文:http://blog.csdn.net/boonya/article/details/8233303 可能大家早先会见过 J-security,这个是 Shiro 的前身.在 2009 年 3 ...
- Python3向网页POST数据
还是以我的网页iciba为例 POST数据到www.selflink.cn/iciba/get0.php获取返回的查询结果 #coding:utf8 import urllib.request imp ...
- 一,彻底理解第一个C语言程序 Hello World
对于初学者来说,第一个程序一般都是hello world,而且是照着书上一点一点敲的.所以,在初学者眼中,敲出来的第一个程序代码不过是一堆看不懂的英语.而事实上,C语言作为一门语言,是有语法的.所以这 ...
- HDU 4121 Xiangqi 模拟题
Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...