转载请注明出处:優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. Myeclipse 快捷键设置和自动提示设置

    1.快捷键设置和调整 2.自动提示信息设置与调整

  2. FIREDAC直连ORACLE数据库

    UniDac对Oracle的Direct连接,不需要套Oracle客户端dll,deploy时真的时 方便又快捷.FireDac连接Oracle,在没有Oracle Client的情况下,是可以连接上 ...

  3. 转载 JQuery中attr属性和JQuery.data()学习

    转载原地址: http://www.cnblogs.com/yeminglong/p/5405745.html 用html直接data-key来存放,key必须全部小写. <div data-m ...

  4. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  5. 网络子系统53_ip协议分片重组_内存阈值

    //调用路径:ip_defrag->ip_evictor // 分片重组时,可使用内存上下限: // 1.sysctl_ipfrag_high_thresh 可用内存上限 // 2.sysctl ...

  6. flex 弹性合模型

    网页布局(layout)是CSS的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂直居中 ...

  7. 被mysql中的wait_timeout坑了

    今天被mysql里的wait_timeout坑了         网上能搜到很多关于mysql中的wait_timeout相关的文章,但是大多数只是说明了他的作用,而且都说这个参数要配合那个inter ...

  8. (转)WordPress的主查询函数-query_posts()

    今天说说WordPress 的主查询函数 -query_posts(),因为我正在制作的主题里面多次用到了这个函数 . query_posts()查询函数决定了哪些文章出现在WordPress 主 循 ...

  9. MATLAB remove outliers.

    Answer by Richard Willey on 9 Jan 2012 Hi Michael MATLAB doesn't provide a specific function to remo ...

  10. java foreach编辑讲解

    foreach语句使用总结 foreach语句是java5的新特征之一,在遍历数组.集合方面,foreach为开发人员提供了极大的方便. foreach语句是for语句的特殊简化版本,但是foreac ...