zoukankan      html  css  js  c++  java
  • POJ 1905 Expanding Rods( 二分搜索 )


    题意:一个钢棍在两面墙之间,它受热会膨胀成一个圆弧形物体,这个物体长 S = ( 1 + n * C ) * L,现在给出原长 L ,温度改变量 n ,和热膨胀系数 C,求膨胀后先后中点的高度差。

    **思路:****戳这里 -> 小優YoU巨巨写的题解挺好的! **

    balabala:
    1. 关键还是得找到变量之间的关系
    2. 输出格式需要注意使用 fixed + setprecision 可以避免输出科学计数法形式的值


    /*************************************************************************
        > File Name: poj1905.cpp
        > Author:    WArobot 
        > Blog:      http://www.cnblogs.com/WArobot/ 
        > Created Time: 2017年05月05日 星期五 15时07分04秒
     ************************************************************************/
    
    #include<iostream>
    #include<cmath>
    #include<cstdio>
    #include<iomanip>
    using namespace std;
    
    #define eps 1e-5
    double L,n,C,S;
    bool check(double h){
    	double r = (L*L+4*h*h)/(8*h);
    	double t = asin(L/(2*r))*2*r;
    	if(S>t)	return 1;		// 说明h偏小
    	else	return 0;		// 说明h偏大
    }
    int main(){
    	while(cin>>L>>n>>C){
    		if(L==-1 && n==-1 && C==-1)	break;
    		S = (1+n*C)*L;
    		double l , r , mid;
    		l = 0;	r = L/2;
    		while(r-l>eps){
    			mid = (r+l)/2;
    			if(check(mid))	l = mid;
    			else			r = mid;
    		}
    		double h = mid;
    		// printf("%.3f
    ",h);
    		cout<<fixed<<setprecision(3)<<h<<endl;
    	}
    	return 0;
    }
  • 相关阅读:
    封装ajax---基于axios
    XHR的理解和作用
    params和 query区别
    HTTP请求交互的基本过程
    http3次握手
    ES6----import * as 用法
    微信小程序真机调试:Setting data field "XXX" to undefined is invalid
    webpack详解-----optimization
    node跨域
    shell 的 功能语句--1
  • 原文地址:https://www.cnblogs.com/WArobot/p/6815286.html
Copyright © 2011-2022 走看看