POJ 1905:Expanding Rods 求函数的二分
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 13780 | Accepted: 3563 |
Description

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
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
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 求函数的二分的更多相关文章
- POJ 1905 Expanding Rods(二分)
Expanding Rods Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 20224 Accepted: 5412 Descr ...
- poj 1905 Expanding Rods(木杆的膨胀)【数学计算+二分枚举】
...
- POJ 1905 Expanding Rods
Expanding Rods Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1 ...
- POJ - 1905 Expanding Rods(二分+计算几何)
http://poj.org/problem?id=1905 题意 一根两端固定在两面墙上的杆,受热后变弯曲.求前后两个状态的杆的中点位置的距离 分析 很明显需要推推公式. 由②的限制条件来二分角度, ...
- poj 1905 Expanding Rods (数学 计算方法 二分)
题目链接 题意:将长度为L的棒子卡在墙壁之间.现在因为某种原因,木棒变长了,因为还在墙壁之间,所以弯成了一个弧度,现在求的是弧的最高处与木棒原先的地方的最大距离. 分析: 下面的分析是网上别人的分析: ...
- POJ 1905 Expanding Rods 二分答案几何
题目:http://poj.org/problem?id=1905 恶心死了,POJ的输出一会要lf,一会要f,而且精度1e-13才过,1e-12都不行,错了一万遍终于对了. #include < ...
- poj 1905 Expanding Rods 二分
/** 题解晚上写 **/ #include <iostream> #include <math.h> #include <algorithm> #include ...
- 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) ...
- POJ 1905 Expanding Rods 木棍膨胀
描述 当长度为L的一根细木棍的温度升高n度,它会膨胀到新的长度L'=(1+n*C)*L,其中C是热膨胀系数. 当一根细木棍被嵌在两堵墙之间被加热,它将膨胀形成弓形的弧,而这个弓形的弦恰好是未加热前木棍 ...
随机推荐
- C++中函数访问数组的方式
在书写C++代码时,往往为了令代码更加简洁高效.提高代码可读性,会对定义的函数有一些特殊的要求:比如不传递不必要的参数,以此来让函数的参数列表尽可能简短. 当一个函数需要访问一个数组元素时,出于上述原 ...
- Linux centosVMware Linux监控平台介绍、zabbix监控介绍、安装zabbix、忘记Admin密码如何做
一.Linux监控平台介绍 cacti.nagios.zabbix.smokeping.open-falcon等等 cacti.smokeping偏向于基础监控,成图非常漂亮 cacti.nagios ...
- 聚合数据实名认证接口-java方法
只需要填入购买的APPKEY,然后直接调用方法JuheDemo.info(user_name, anchor_card);传入姓名和身份证号,根据获取的返回参数进行拆分,如res=1说明正确. //进 ...
- ES5 Object.assign 低版本浏览器内核兼容问题
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { ...
- package.json中一些配置项的含义
{ "name": "webpack-demo", "version": "1.0.0", "de ...
- docsify简单教程
简介 一个神奇的文档网站生成器. 简单而轻便(〜18kB压缩) 没有静态构建的HTML文件 多个主题 快速开始 建议docsify-cli全局安装,这有助于本地初始化和预览网站. npm i docs ...
- Springboot 项目启动设置
//配置默认访问路径 并且自动打开浏览器 需要创建独立文件 @Controller public class HomeController { @RequestMapping("/ ...
- 吴裕雄--天生自然HADOOP操作实验学习笔记:pig简介
实验目的 了解pig的该概念和原理 了解pig的思想和用途 了解pig与hadoop的关系 实验原理 1.Pig 相比Java的MapReduce API,Pig为大型数据集的处理提供了更高层次的抽象 ...
- A. Hotelier
A. Hotelier 题意:一家有10间房间的旅馆(10个房间排成一排),在旅馆的左右两端都有一个办理入住的前台,L代表在左端办理入住,R代表在右端办理入住,顾客都会挑选距离最近的空房间入住,数 ...
- PaperReading20200221
CanChen ggchen@mail.ustc.edu.cn Busy... Human-level concept learning through probabilistic program i ...