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. 监听EditView中的文本改变事件详解--转

    转自: http://blog.csdn.net/zoeice/article/details/7700529 android中的编辑框EditText也比较常用,那比如在搜索框中,没输入一个字,下面 ...

  2. 七 异常处理的两种方式(创建全局异常处理器&自定义异常)

    1 创建全局异常处理器 实现HandlerExceptionResolve接口 package com.springmvc01; import javax.servlet.http.HttpServl ...

  3. Django链接MySQL,数据库迁移

    form表单默认是以get请求提交数据的 http://127.0.0.1:8000/login/?username=admin&password=123 action 1 不写,默认向当前地 ...

  4. 第2节 storm实时看板案例:11、实时看板综合案例工程构建,redis的专业术语

    redis当中的一些专业术语: redis缓存击穿 redis缓存雪崩 redis的缓存淘汰 =========================================== 详见代码

  5. day14-Python运维开发基础(内置函数、pickle序列化模块、math数学模块)

    1. 内置函数 # ### 内置函数 # abs 绝对值函数 res = abs(-10) print(res) # round 四舍五入 (n.5 n为偶数则舍去 n.5 n为奇数,则进一!) 奇进 ...

  6. ELK/EFK——日志收集分析平台

    ELK——日志收集分析平台 ELK简介:在开源的日志管理方案之中,最出名的莫过于ELK了,ELK由ElasticSearch.Logstash和Kiabana三个开源工具组成.1)ElasticSea ...

  7. Kubernetes——机密数据管理

    k8s——机密数据管理1.secret2.configMap kubectl explain secret    #查看帮助手册然后将你要加密的变量值做些许处理:echo 123 | base64   ...

  8. unity3d Asset Store下载的资源在哪?

    win7 C:\Users\(用户名)\AppData\Roaming\Unity\Asset Store\ 用户名为中文的时候,是不能直接在unity3d中打开的.

  9. 一 CRM 注册功能实现

    前端:登陆页面按钮跳转到注册页面 dao:  配置连接池 配置session工厂,Hibernate核心配置,映射 配置UserDao,注入session工厂 UserDao:继承HibernateD ...

  10. 性能测试中TPS上不去的几种原因

    性能测试中TPS上不去的几种原因 什么叫TPS: TPS(Transaction Per Second):每秒事务数,指服务器在单位时间内(秒)可以处理的事务数量,一般以request/second为 ...