转载请注明出处:優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)(二分+几何)的更多相关文章

  1. Expanding Rods(二分POJ1905)

    Expanding Rods Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13688   Accepted: 3527 D ...

  2. POJ 1905 Expanding Rods 二分答案几何

    题目:http://poj.org/problem?id=1905 恶心死了,POJ的输出一会要lf,一会要f,而且精度1e-13才过,1e-12都不行,错了一万遍终于对了. #include < ...

  3. Expanding Rods(二分)

    Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10287   Accepted: 2615 Description When ...

  4. poj 1905 Expanding Rods 二分

    /** 题解晚上写 **/ #include <iostream> #include <math.h> #include <algorithm> #include ...

  5. UVA 10668 - Expanding Rods(数学+二分)

    UVA 10668 - Expanding Rods 题目链接 题意:给定一个铁棒,如图中加热会变成一段圆弧,长度为L′=(1+nc)l,问这时和原来位置的高度之差 思路:画一下图能够非常easy推出 ...

  6. 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 ...

  7. POJ 1905:Expanding Rods 求函数的二分

    Expanding Rods Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13780   Accepted: 3563 D ...

  8. POJ 1905 Expanding Rods(二分)

    Expanding Rods Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 20224 Accepted: 5412 Descr ...

  9. poj 1905 Expanding Rods(木杆的膨胀)【数学计算+二分枚举】

                                                                                                         ...

随机推荐

  1. Delphi异形窗口之PNG

    //1.单元内容 unit UnitAlienForm; interface uses Windows, Forms, Classes, Graphics; //从文件加载PNG procedure ...

  2. [C语言 - 8] 枚举enum

    枚举是c语言中得一种基本数据类型,不是数据结构 用于声明一组常数 1. 3中枚举变量的方式 a. 先定义类型, 再定义变量 b. 同时定义类型和变量 c. 匿名定义 enum Season {Spri ...

  3. Cannot retrieve metalink for repository: epel. Please verify its path and try again

    今天在测试环境使用yum安装,遇到一个问题: Error: Cannot retrieve metalink for repository: epel. Please verify its path ...

  4. HDU 5835 Danganronpa (水题)

    题意:给定 n 个礼物有数量,一种是特殊的,一种是不特殊的,要分给一些人,每人一个特殊的一个不特殊,但是不特殊的不能相邻的,问最多能分给多少人. 析:是一个比较简单的题目,我们只要求差值就好,先算第一 ...

  5. 一个简单的hibernate项目

    准备工作 工具准备 hibernate3.5.3 Eclipse Java EE IDE for Web Developers.Version: Helios MySQL5.5 环境配置搭建 安装并配 ...

  6. IOS学习网址

    iOS定位和位置信息获取 http://www.cnblogs.com/496668219long/p/4471757.html iOS开发系列--并行开发其实很容易 http://www.cnblo ...

  7. rsync服务架设(数据同步|文件增量备份)

        近期由于业务需要,需要将两台服务器数据保持同步.方案有很多,rsync是其中一种解决方案,本文对rsync的安装及配置进行简单说明,其他实现方式有兴趣可以研究.以下是本文提纲,供参考: rsy ...

  8. hihocoder #1223 : 不等式 水题

    #1223 : 不等式 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/1223 ...

  9. ios开发——实用技术篇Swift篇&录音

    录音 // MARK: - 录音 /*----- 录音 ------*/ var recorder:AVAudioRecorder? //录音器 var player:AVAudioPlayer? / ...

  10. 从user 登陆開始

    首先.我们来看看我们的需求,看看需求里有没有你感兴趣的知识点: 用户登陆: 实现用户从网页登陆界面输入正确的username.password及验证码后跳转到一个页面显示登陆成功 要求:  1. 数据 ...