zoukankan      html  css  js  c++  java
  • hdu 5060 五种情况求圆柱体与球体交

    http://acm.hdu.edu.cn/showproblem.php?pid=5060

    官方题解http://bestcoder.hdu.edu.cn/给复杂了

    实际上用圆柱体与球体体积差的积分公式(pi*r*r - pi*x*x)即可轻松解决五种情况

    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <queue>
    #include <set>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define RD(x) scanf("%d",&x)
    #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define clr0(x) memset(x,0,sizeof(x))
    typedef long long LL;
    
    const double pi = acos ( -1.0 ) ;
    
    int R , HR , HZ ;
    
    
    double f2 ( double x1 , double x2 ) {
    	return R * R * pi * ( x2 - x1 ) - 1.0 / 3.0 * pi * ( x2 * x2 * x2 - x1 * x1 * x1 ) ;
    }
    
    int solve () {
    	double V1 = pi * R * R * R * 4.0 / 3.0 ;
    	double V2 = 2.0 * HR * HR * pi * HZ ;
    	if ( HR * HR + HZ * HZ <= R * R ) {
    		printf ( "%.6f
    " , V2 / V1 ) ;
    	} else if ( HR >= R && HZ >= R ) {
    		printf ( "%.6f
    " , V1 / V2 ) ;
    	} else {
    	    double V;
    	    if ( HR <= R && HZ <= R ) {
                double y1 = HZ ;
                double y2 = sqrt ( R * R - HR * HR ) ;
                V = 2.0 * ( HR * HR * y2 * pi + f2 ( y2 , R ) - f2 ( y1 , R ) ) ;
            } else if ( HR > R && HZ <= R ) {
                double y1 = HZ ;
                double y2 = 0 ;
                V = 2.0 * ( f2 ( y2 , R ) - f2 ( y1 , R ) ) ;
            } else if ( HR <= R && HZ >= R ) {
                double y = sqrt ( R * R - HR * HR ) ;
                V = 2.0 * ( HR * HR * y * pi + f2 ( y , R ) ) ;
            }
            printf ( "%.6f
    " , V / ( V1 + V2 - V ) ) ;
    	}
    }
    
    int main () {
    	while ( ~RD3(R , HR , HZ ) )
            solve () ;
    	return 0 ;
    }
    


  • 相关阅读:
    自定义转化
    asp.net JSON(一)
    做一个会偷懒的码农
    活动和监视器
    linq 分组求和
    sql语句查询列的说明
    chartControl
    LayOutControl
    sql 给表结构增加说明
    我的单件模式
  • 原文地址:https://www.cnblogs.com/zibaohun/p/4046829.html
Copyright © 2011-2022 走看看