POJ 1905 题解(二分+几何)
题面
分析
如图:已知AB=L,弧AB=L(1+nC)" role="presentation" style="position: relative;">AB=L,弧AB=L(1+nC)AB=L,弧AB=L(1+nC),M为AB中点,N为圆上一点,且ON垂直于AB于M,求MN
设半径为R" role="presentation" style="position: relative;">RR,∠AOM=θ" role="presentation" style="position: relative;">∠AOM=θ∠AOM=θ(弧度),MN=x" role="presentation" style="position: relative;">MN=xMN=x
则可列出方程组
{2Rθ=L(1+nc)(1)Rsinθ=L2(2)x=R(1−cosθ)(3)" role="presentation" style="position: relative;">⎧⎩⎨⎪⎪⎪⎪2Rθ=L(1+nc)(1)Rsinθ=L2(2)x=R(1−cosθ)(3){2Rθ=L(1+nc)(1)Rsinθ=L2(2)x=R(1−cosθ)(3)
若求出θ" role="presentation" style="position: relative;">θθ便可以求出x,所以我们从 θ" role="presentation" style="position: relative;">θθ入手,尝试解上面的方程组
由(1)(2)式得 θsinθ=1+nC" role="presentation" style="position: relative;">θsinθ=1+nCθsinθ=1+nC
本人数学不好,求不出上面的方程的解析解(如果有解析解可以在评论中指出)
于是采用二分的方法来近似求根
显然0<θ≤π2" role="presentation" style="position: relative;">0<θ≤π20<θ≤π2
由图知θ" role="presentation" style="position: relative;">θθ越大,1+nC越大" role="presentation" style="position: relative;">1+nC越大1+nC越大
我们二分θ" role="presentation" style="position: relative;">θθ,设二分中点为mid,端点为[L,R]并计算midsinmid" role="presentation" style="position: relative;">midsinmidmidsinmid,若midsinmid>1+nC" role="presentation" style="position: relative;">midsinmid>1+nCmidsinmid>1+nC,则寻找更小的,R=mid.否则寻找更大的,L=mid
还有几个细节:
1.π" role="presentation" style="position: relative;">ππ一定要很精确,否则会WA
2.设定的二分误差要尽量小
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define eps 1e-11
#define pi 3.141592653589793
using namespace std;
double L,n,C,theta,x;
int main(){
while(scanf("%lf %lf %lf",&L,&n,&C)!=EOF){
if(L==n&&n==C&&C==-1) break;
if(n*C==0){
printf("0.000\n");
continue;
}
double l=eps,r=pi/2;//用弧度表示角
while(fabs(l-r)>eps){
double mid=(l+r)/2;
double hu=mid/sin(mid);
if(hu>1+n*C) r=mid;
else l=mid;
}
theta=l;
double R=L/(2*sin(theta));
printf("%.3f\n",R*(1-cos(theta)));
}
}
POJ 1905 题解(二分+几何)的更多相关文章
- D - Expanding Rods POJ - 1905(二分)
D - Expanding Rods POJ - 1905 When a thin rod of length L is heated n degrees, it expands to a new l ...
- POJ 1840 Eqs 二分+map/hash
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...
- poj 2318 叉积+二分
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13262 Accepted: 6412 Description ...
- poj 2049(二分+spfa判负环)
poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根 ...
- POJ 1905 Expanding Rods 二分答案几何
题目:http://poj.org/problem?id=1905 恶心死了,POJ的输出一会要lf,一会要f,而且精度1e-13才过,1e-12都不行,错了一万遍终于对了. #include < ...
- POJ - 1905 Expanding Rods(二分+计算几何)
http://poj.org/problem?id=1905 题意 一根两端固定在两面墙上的杆,受热后变弯曲.求前后两个状态的杆的中点位置的距离 分析 很明显需要推推公式. 由②的限制条件来二分角度, ...
- 【二分答案】Expanding Rods POJ 1905
题目链接:http://poj.org/problem?id=1905 题目大意:原长度为L的线段因受热膨胀为一段弧,线段L.弧长L'.温度n.膨胀率c满足L' =(1+n/c)*L;求线段的中点移动 ...
- poj 3061 题解(尺取法|二分
题意 $ T $ 组数据,每组数据给一个长度 $ N $ 的序列,要求一段连续的子序列的和大于 $ S $,问子序列最小长度为多少. 输入样例 2 10 15 5 1 3 5 10 7 4 9 2 8 ...
- poj 1905 Expanding Rods (数学 计算方法 二分)
题目链接 题意:将长度为L的棒子卡在墙壁之间.现在因为某种原因,木棒变长了,因为还在墙壁之间,所以弯成了一个弧度,现在求的是弧的最高处与木棒原先的地方的最大距离. 分析: 下面的分析是网上别人的分析: ...
随机推荐
- vue请求数据
vue-resource: 推荐教程:https://www.runoob.com/vue2/vuejs-ajax.html 1. 需要安装vue-resource模块, 注意加上 --save np ...
- 对npm的认识
npm由三个不同的组件组成:1,网站 2.命令行界面(CLI)3.注册表 需要在网站注册 命令行界面用来进行交互 注册表来进行保存 安装本地软件包 npm install 包名 更新本地软件包 npm ...
- jetSonNano darknet ubdefined reference to 'pow',undefined reference to 'sqrtf'....
我在用CMakelist编译工程时,遇到了这个一连串基础数学函数找不到的问题,如下图所示: 我当时在工程中明明引用了 #include "math.h"头函数,这是因为你的工程在预 ...
- sass、less中的scoped属性
1.scoped 的实现原理 Vue中的Less 中的 scoped 属性的效果主要是通过 PostCss 实现的.代码示例: //编译前 <template> <div class ...
- POJ 2456 Aggressive cows ( 二分 && 贪心 )
题意 : 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,...,xN (0 <= xi <= 1e9) ...
- Leetcode 14. Longest Common Prefix(水)
14. Longest Common Prefix Easy Write a function to find the longest common prefix string amongst an ...
- H. The Game of Life
题目链接:http://exam.upc.edu.cn/problem.php?id=5206 题意:邻居为八个方向.若一个活人有2或3个邻居,遗传一代,否则死亡:若一个死人有3个邻居,则下一代复活. ...
- H-ui.admin v3.1学习之路(一):导航栏信息无法在内容区显示
注:我使用的是别人的模板文件在我的云盘“素材模板—H-ui.admin’中. 直接上代码: <li class="dropDown dropDown_hover"> & ...
- 170826-关于spring的知识点及练习
1.Spring作用: 1.生态体系庞大,全能型选手![springmvc是其一个子模块,jdbcTemplate能直接操作数据库!] 2.将其他组件粘合在一起 3.IOC容器和AOP[Aspect ...
- 基于vue模块化开发后台系统——构建项目
文章目录如下:项目效果预览地址项目开源代码基于vue模块化开发后台系统--准备工作基于vue模块化开发后台系统--构建项目基于vue模块化开发后台系统--权限控制 前言 在熟悉上一篇说到准备工具之后, ...