POJ 1905: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
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是热膨胀系数. 当一根细木棍被嵌在两堵墙之间被加热,它将膨胀形成弓形的弧,而这个弓形的弦恰好是未加热前木棍 ...
随机推荐
- Java垃圾回收与内存
好久没看关于java的书了, 最近, 看了James Gosling的<<Java程序设计语言>>, 做了一些读书笔记. 这部分是关于垃圾回收的. 1.垃圾回收 对象是使用ne ...
- 图解jvm--(三)类加载与字节码技术
类加载与字节码技术 1.类文件结构 根据 JVM 规范,类文件结构如下 ClassFile { u4 magic; //魔数 u2 minor_version; //小版本号 u2 major_ver ...
- APNs推送的系统做法
1. #pragma mark - 远程推送注册获得device Token if (IOS_VERSION >= 10.0) { UNUserNotificationCenter * cent ...
- idea配置使用
1.下载时注意连带下载git 2.实时清除内存 打开 show memory indicator 3.插件安装 前端常用插件(vue,element,css,html,node,ts等)找到适合自己 ...
- mysql odbc 配置详解
1.安装mysql 以及mysql odbc 要注意自己的版本 版本都要统一(32位 或者64位) 2.出现的error 1989 126错误代码 Error 1918. Error installi ...
- JavaScript高级程序设计(第3版)每章小结(1-5)
第一章 JavaScript的简介 第二章 在HTML中使用JavaScript 把JavaScript插入到HTML页面中要使用<Script>元素.使用这个元素可以把JavaScrip ...
- 新建Django 项目完整流程
1) 在桌面或者其他文件 新建项目名称 (mkdir 新建文件夹) 2)进入文件夹 pipenv --python3(用命令提示粘贴复制, 自己这样写经常有问题) 3) 启动虚拟环境 pipenv ...
- BurpSuite 1.7.32 Cracked 破解版[注册机]下载【无后门版】
首先看一下我的注册后的: 注册机的使用也很简单,首先打开burp-loader-keygen.jar文件,然后随便填写license text,比如我填写的是:mrxn.net效果如下图: 然后点击m ...
- DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "XXX" failed with error code 0xC0209303.
问题: 今天写了一个新的SSIS的ETL包,运行报如下错误. DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnec ...
- PHP的错误知识
一.绪 PHP程序的错误发生一般归属于: 语法错误(会阻止脚本的执行) 运行时错误(不会阻止脚本的执行,但会组织脚本做希望它做的任何事情) 逻辑错误(不会阻止脚本执行,也不会显示错误消息) 二.开启错 ...