POJ1905 Expanding Rods 题解&代码
来源:互联网 发布:php跳转到指定页面代码 编辑:程序博客网 时间:2024/05/16 20:29
题意:
给出一个长L的木棒,给出温度n和膨胀系数C。
已知木棒的长度S遵循公式S=L*(1+n*C)
如图,图源自 小優YoU
求当一根木棒如此膨胀时形成的弧形中心位置和原来的中心位置之间的距离h
思路:暴力几何题…主要是一些公式推导,如下【依照代码的变量命名,即上文S均为L0
① L0=(1+n*C)*L
② L=2*sqrt(R*R-(R-h)*(R-h))
③ S=2*pi*R*((2*theta)/(2*pi))
④sin(theta)=L/(2*R)
由①式求出L0
②式可以变形为R=(L*L)/(8*h)+h/2
③式和④式可以表达出S=2*arcsin(L/(2*R))*R
于是我们二分h,对每次二分出的h计算出S
如果S和L0相等【eps判断】那么得到答案
如果S小于L0那么我们的h一定是算小了【可以很容易脑补…】
反之则反
重点其实不在于这里…而是…我又WA了两次还是三次…死于%lf
对!读入要用%lf但是POJ上一定要用%f输出double类型!
#include<iostream>#include<cstdio>#include<cmath>#define EPS 1e-6using namespace std;double L,n,C,L0,l,r,mid,theta,R;bool check(double x){ R=(L*L)/(8.0*x)+x/2.0; if(2.0*R*asin(L/(2.0*R))<L0)return false; return true;}int main(void){ while(scanf("%lf%lf%lf",&L,&n,&C)) { if(L<0 && n<0 && C<0)break; L0=(1.0+n*C)*L; l=0.0;r=L/2.0; while(r-l>EPS) { mid=(l+r)/2.0; if(check(mid))r=mid; else l=mid; } printf("%.3f\n",l); } return 0;}
0 0
- POJ1905 Expanding Rods 题解&代码
- POJ1905[Expanding Rods]题解
- POJ1905 Expanding Rods 二分
- POJ1905:Expanding Rods
- POJ1905 Expanding Rods
- POJ1905--Expanding Rods
- POJ1905 Expanding Rods
- poj1905 Expanding Rods
- POJ1905 Expanding Rods
- poj1905 Expanding Rods 二分
- 二分 poj1905 Expanding Rods
- POJ1905-Expanding Rods - 二分法。
- Expanding Rods(二分POJ1905)
- POJ1905-----Expanding Rods
- Expanding Rods<poj1905>
- poj1905 Expanding Rods
- [POJ1905]Expanding Rods
- POJ1905 Expanding Rods(二分)
- cocos2dx3.3视频播放的实现VideoPlayer的使用
- get与post小记
- Real-time model scoring for streaming data – a prototype based on Oracle Stream Explorer and Oracle
- (js特效) js代码实现弹出层
- 快速排序
- POJ1905 Expanding Rods 题解&代码
- win7磁盘分区
- 【笔记】 《js权威指南》- 第3章 类型、值和变量 - 3.8 类型转换
- tabBar控制器,跳转到指定的页面
- 矩阵翻转
- Red Hat 4-5-6 使用在线Oracle 公共YUM
- bootstrap ace admin 整合java HTML5 全新高大尚web后台框架
- Libevent源码分析(七)--- IOCP
- 阿里云ECS服务器 phpwind9.0安装