博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Expanding Rods 二分查找(精度很重要)
阅读量:6228 次
发布时间:2019-06-21

本文共 2163 字,大约阅读时间需要 7 分钟。

Problem Description
1905_1.jpgWhen 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=R*a(角度);设弦长为L0,则sin(a/2)=(L0/2)/R;则(a/2)=asin((L0/2)/R);则a=2*asin((L0/2)/R);
**************************************************************************************************************************
ContractedBlock.gif
ExpandedBlockStart.gif
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 //#define PI 3.1415926535897932 8 using namespace std; 9 double esp=1e-6;10 double L0,L1,n,c,L2,mid,r;11 double high,low;12 int main()13 {14 while(scanf("%lf%lf%lf",&L0,&n,&c)&&L0>=0&&n>=0&&c>=0)15 {16 L1=(1+n*c)*L0;17 //printf("L0:%lf L1:%lf\n",L0,L1);18 high=0.5*L0;19 low=0.0;20 while(high-low>esp)21 {22 mid=(high+low)/2;23 r=(L0*L0+4*mid*mid)/(8*mid);24 L2=2*r*asin(L0/(2*r));25 if(L2<=L1)low=mid;26 else27 high=mid;28 }29 mid=(high+low)/2;30 printf("%.3lf\n",mid);31 }32 return 0;33 }
View Code

转载于:https://www.cnblogs.com/sdau--codeants/p/3377895.html

你可能感兴趣的文章
nginx安装步骤总结-故障排查-浏览原理
查看>>
菜鸟学Linux 第071篇笔记 Mysql理论
查看>>
LINUX REDHAT第十四单元文档
查看>>
Java线程间通信之wait/notify
查看>>
jstat监控JVM内存使用情况、GC回收情况
查看>>
PHP ElasticSearch的使用
查看>>
python将日志导入数据库代码案例 3
查看>>
IOS之分析网易新闻存储数据(CoreData的使用,增删改查)
查看>>
php获取一维,二维数组长度的方法(有实例)
查看>>
iOS:KVO的概述与使用
查看>>
CLI使用案例4:灵活配置CLI
查看>>
Oracle12C 单实例dataguard配置
查看>>
MySQL入门介绍
查看>>
记JIRA服务,数据迁移,安装配置
查看>>
Linux下面监控系统性能的工具-vmstat
查看>>
Java Collection集合方法
查看>>
MySQL备份与恢复
查看>>
Linux---管理网络
查看>>
Can't load '/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/DBD/mysql/mysql.so&#
查看>>
Ubuntu下nagios安装pnp4nagios插件
查看>>