poj 1905 Expanding Rods(二分)
来源:互联网 发布:python 集合操作 编辑:程序博客网 时间:2024/04/28 06:16
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.
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.000115000 10 0.0000610 0 0.001-1 -1 -1
Sample Output
61.329225.0200.000
Source
看似是个几何问题应该列方程组求问题,但是却无法求出,因此根据题上所说的H的范围,下线是0,上线就是L/2;
根据公式,最后我们可以得出
double r=(4*mid*mid+l*l)/(8*mid);
double s=2*r*asin(l/(2*r));
double s=2*r*asin(l/(2*r));
然后二分枚举找出H的值
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<math.h>#include<string>#include<iomanip>using namespace std;typedef long long ll;const double esp=1e-5;double l,n,c;int main(){ while(cin>>l>>n>>c) { if(l<0&&n<0&&c<0) break; //如果l,n,c都小于0输入结束 double L=(1+n*c)*l; //求出弧的长度 double last=0.5*l; double mid; double first=0.0; while(last-first>esp) { mid=(first+last)/2; double r=(4*mid*mid+l*l)/(8*mid); double s=2*r*asin(l/(2*r)); if(s<L) first=mid; else last=mid; } double h=mid; cout<<fixed<<setprecision(3)<<h<<endl; 最后我在这里有了疑问,后来测试了一下,setprecision()函数在第四位小数是5的时候不进位,而用printf就会四舍五入,因此以后再做类似的题还是先把浮点数转化为整数,这样会容易的多,避免的四舍五入时精度不准 } return 0;}
0 0
- poj-1905 Expanding Rods (二分)
- POJ 1905 Expanding Rods(二分)
- POJ 1905 Expanding Rods(二分)
- POJ 1905Expanding Rods(计算二分)
- POJ 1905 Expanding Rods (二分)
- POJ - 1905 Expanding Rods (数学+二分)
- poj 1905 Expanding Rods(二分)
- POJ 1905 Expanding Rods(二分)
- POJ 1905 Expanding Rods(二分)
- POJ 1905 Expanding Rods(二分搜索)
- POJ 1905 Expanding Rods(二分)
- poj--1905 Expanding Rods(二分)
- 【POJ 1905】 Expanding Rods (二分)
- POJ 1905 Expanding Rods二分
- poj 1905 Expanding Rods(二分)
- POJ Expanding Rods 1905 (二分)
- POJ 1905 Expanding Rods 解题报告(二分)
- POJ 题目1905 Expanding Rods(二分,数学几何)
- parseInt(),parseFloat()
- hdu--1896Stones(优先队列)
- 资料链接
- Java Info basic 1
- 浅谈基础数论
- poj 1905 Expanding Rods(二分)
- 动态规划-leetcode小结
- PAT 1086 Tree Traversals Again
- Base64编码、解码 C语言例子(使用OpenSSL库)
- 剑指offer 二叉树的镜像
- Gradle sync failed: Java home is different
- Socket通信,TCP/IP和HTTP的理解
- GCC中x86架构下simd intrinsic函数的实现的分析
- Go语言学习笔记 -- array、slice和map