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

Description

When a thin rod of length L is heated n degrees, it expands to a new length L'=(1+n*C)*L, where C is the coefficient of heat expansion. 

When a thin rod is mounted on two solid walls and then heated, it expands and takes the shape of a circular segment, the original rod being the chord of the segment. 



Your task is to compute the distance by which the center of the rod is displaced. 

Input

The input contains multiple lines. Each line of input contains three non-negative numbers: the initial lenth of the rod in millimeters, the temperature change in degrees and the coefficient of heat expansion of the material. Input data guarantee that no rod
expands by more than one half of its original length. The last line of input contains three negative numbers and it should not be processed.

Output

For each line of input, output one line with the displacement of the center of the rod in millimeters with 3 digits of precision. 

Sample Input

1000 100 0.0001
15000 10 0.00006
10 0 0.001
-1 -1 -1

Sample Output

61.329
225.020
0.000

题意是一根长度为L的木棒,加热n度之后长度变为L'=(1+n*C)*L,其中C是木棒的热膨胀系数。给出L,n,C。求木棒在加热前后中心点的距离是多少。

四个方程:(假设要求的距离为x)

L'=(1+n*C)*L

θr = 1/2*L'

sinθ= 1/2*L/r

r*r = (1/2*L)*(1/2*L) + (r-x)*(r-x)

这个题目有意思的地方在于导出x非常困难,所以只能枚举x的值,然后能够得到r的值,然后去带入方程2 3,去和正确值比较。导出最终的函数是一个单调性函数,所以直接二分。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; #define esp 1e-5 double L, N, C, S; bool check(double mid)
{
double ans = 2 * asin((L / 2) / ((L*L + 4 * mid*mid) / (8 * mid)))*((L*L + 4 * mid*mid) / (8 * mid));
return ans >= S;
} int main()
{
//freopen("i.txt","r",stdin);
//freopen("o.txt","w",stdout); double left, right, mid; while (cin>>L>>N>>C)
{
if (L + N + C < 0 )
break;
S = (1 + N*C)*L;
left = 0.0;
right = L/2; while (right - left > esp)
{
mid = (right + left) / 2;
if (check(mid))
{
right = mid;
}
else
{
left = mid;
}
}
printf("%.3lf\n",right);
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1905:Expanding Rods 求函数的二分的更多相关文章

  1. POJ 1905 Expanding Rods(二分)

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

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

                                                                                                         ...

  3. POJ 1905 Expanding Rods

                           Expanding Rods Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1 ...

  4. POJ - 1905 Expanding Rods(二分+计算几何)

    http://poj.org/problem?id=1905 题意 一根两端固定在两面墙上的杆,受热后变弯曲.求前后两个状态的杆的中点位置的距离 分析 很明显需要推推公式. 由②的限制条件来二分角度, ...

  5. poj 1905 Expanding Rods (数学 计算方法 二分)

    题目链接 题意:将长度为L的棒子卡在墙壁之间.现在因为某种原因,木棒变长了,因为还在墙壁之间,所以弯成了一个弧度,现在求的是弧的最高处与木棒原先的地方的最大距离. 分析: 下面的分析是网上别人的分析: ...

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

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

  7. poj 1905 Expanding Rods 二分

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

  8. POJ 1905 Expanding Rods (求直杆弯曲拱起的高度)(二分法,相交弦定理)

    Description When a thin rod of length L is heated n degrees, it expands to a new length L' = (1+n*C) ...

  9. POJ 1905 Expanding Rods 木棍膨胀

    描述 当长度为L的一根细木棍的温度升高n度,它会膨胀到新的长度L'=(1+n*C)*L,其中C是热膨胀系数. 当一根细木棍被嵌在两堵墙之间被加热,它将膨胀形成弓形的弧,而这个弓形的弦恰好是未加热前木棍 ...

随机推荐

  1. Centos7 更新配置为阿里源步骤

    一.yum更换配置源过程 1.备份原有的.repo源文件 首先需要将之前的源进行备份(一般重要的配置文件都需要有备份的意识) # 进入源配置目录 cd /etc/yum.repos.d # 创建备份文 ...

  2. 《java核心技术:卷1》PDF版 和 Word版下载

    链接:https://pan.baidu.com/s/1OcpdZ4wfeo55xeJQQBHXRg 提取码:hds0

  3. python下载图片的代码块

    import urllib.requestimgurl="https://ss3.baidu.com/9fo3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/si ...

  4. Java 理论与实践: 哈希

    有效和正确定义hashCode()和equals() 每个Java对象都有 hashCode() 和 equals() 方法.许多类 Override 这些方法的缺省实施,以在对象实例之间提供更深层次 ...

  5. 暑假周进度报告(三)-------版本过高后续问题处理,eclipse编译运行MapReduce以及Hadoop学习

    问题一:Hadoop版本太高 卸载Hadoop3.2.0 我改安装了Hadoop 2.7.7 如果没有权限下载.可以采用如下方式: 卸载完成以后返回原目录即可 后面的jdk卸载也可以采用这种方式. 按 ...

  6. Java 代码空间复杂度查看工具

    SourceMonitor 下载地址:http://www.campwoodsw.com/sourcemonitor.html

  7. 指定GPU运行python程序

    一.命令行运行python程序时 1.首先查看哪些GPU空闲,nvidia-smi显示当前GPU使用情况. nvidia-smi 2.然后指定空闲的GPU运行python程序. CUDA_VISIBL ...

  8. 有关《查找两个List中的不同元素》的问题解答与编程实践

     郑海波 2013-07-08 问题: 有List<String> list1和List<String> list2,两个集合各有上万个元素,怎样查找两个集合中不同的元素呢? ...

  9. 侧边栏下拉时箭头的旋转动画(treeView控件)

    //点击菜单时箭头旋转 let treeView = document.getElementsByClassName("treeview");//let解决闭包问题 let las ...

  10. Mybatis注解开发单表CRUD

    Mybatis注解开发单表CRUD mybatis注解开发和xml开发不可兼容,要么全部使用注解,要么全部使用xml,个人建议注解,简单. 当实体类属性名称和数据库表属性名称一致时:无需配置Resul ...