转载请注明出处:優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. HDU 5752 Sqrt Bo (数论)

    Sqrt Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5752 Description Let's define the function f ...

  2. hdu 1689 Just a Hook

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 Just a Hook Time Limit: 4000/2000 MS (Java/Others)    ...

  3. [iOS基础控件 - 6.10.5] UIApplication

    A.概念 1.UIApplication对象是应用程序的象征,每个应用都有 2.单例 3.[UIApplication sharedApplication] 获取 4.iOS启动创建的第一个对象 5. ...

  4. POJ 3670 Eating Together (DP,LIS)

    题意:给定 n 个数,让你修改最少的数,使得它变成一个不下降或者不上升序列. 析:这个就是一个LIS,但是当时并没有看出来...只要求出最长LIS的长度,用总数减去就是答案. 代码如下: #inclu ...

  5. 关于spring管理hibernate事物

    下面这篇文章对我帮助很大.http://blog.csdn.net/jianxin1009/article/details/9202907

  6. Python3学习

    要做一个儿童搜索引擎的项目(www.kidsearch.cn),所以开始接触各种新的语言,初步学了PHP爬虫,觉得要做大点的项目用PHP确实不太方便,中文兼容性就是一个比较棘手的问题.python的爬 ...

  7. POJ 1979 dfs和bfs两种解法

      fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream&g ...

  8. CustomerSOList

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  9. 读取AD模拟分量

    //EEPROM数据保存---------------------- #include <EEPROM.h> #define EEPROM_write(address, p) {int i ...

  10. Codeforces Round #313 (Div. 2) A. Currency System in Geraldion 水题

    A. Currency System in Geraldion Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...