二分法 (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(木杆的膨胀)【数学计算+二分枚举】
...
随机推荐
- 【转】并发编程之GCD
http://blog.xcodev.com/blog/2013/11/04/gcd-intro/ Dispatch Queue Dispatch Queue是一个任务执行队列,可以让你异步或同步地执 ...
- POJ 3026 Borg Maze (最小生成树)
Borg Maze 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/I Description The Borg is an im ...
- SaltStack 最新版WebUI部署
saltstack web uiweb平台界面 saltapi项目主页:http://salt-api.readthedocs.org/en/latest/ halite 项目主页:https://g ...
- hdu 1443 Joseph (约瑟夫环)
Joseph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- linux下安装apache详解
下载httpd-2.2.6.tar.bz2 把httpd-2.2.6.tar.bz2放到/soft 下[root@localhost ~]#cd /soft[root@localhost soft] ...
- 分析恶意驱动(进程启动apc注入dll)
一.前言 用IDA也有好些时间了,以前就只会用F5功能玩无壳无保护的裸驱动,感觉太坑了,这两天就开始看网上大牛的逆向. 今天记录一下sudami曾经逆向过的fuck.sys.第一遍自己走的时候漏掉了 ...
- android开发教程(八)——环境搭建之java-ndk
目录 android ndk是android用于开发本地代码的开发工具包.它提供C/C++交叉编译工具.android内核.驱动.已有的C/C++代码,都需要ndk来支持开发. 目前支持以下平台:ar ...
- ListCtrl控件的使用
list contrl控件的使用 .建立基于对话框的应用程序,布置界面,设置属性. 注意添加的是listctrl控件,不是listbox控件,在控件工具箱的倒数第五行list control控件. 属 ...
- AJAX顺序输出
转载:http://www.cnblogs.com/niunan/archive/2010/10/13/1849873.html AJAX顺序输出 在安装大多数CMS的时候都会在安装界面上看到这样的 ...
- Spring 的两个配置容器的讲解
容器 是Spring框架的核心,是组件存活的地方.Spring容器使用DI管理所有组成应用系统的组件,协作组件之间建立联.而且, 这些对象简洁易懂,降低耦合性,支持重用,容易被测试. Spring提供 ...