ZOJ 3922 Candy with chocolate(几何)

写过几次吧

第一次想到方法,但是没想到正多面体只有5种

第二次的时候手头没有计算公式


因为是体积扩展,所以必然是面积*h,还有棱上的圆柱体,以及定点上的圆弧,圆柱体的体积是和二面角的补角有关。定点的话所有的定点之和可以凑成一个圆


#include <cstdio>  
#include <cstring>  
#include <algorithm>  
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
const int maxn = 57;
#define MAXN 100005
#define ll long long
#define PI acos(-1.0)

int main()
{
	int T;
	cin >> T;
	map<int, int>ma;
	ma[4] = 6;
	ma[8] = 12;
	ma[12] = 30;
	ma[20] = 30;
	ma[6] = 12;
	while (T--)
	{
		int n, l, h;
		cin >> n >> l >> h;
		double ans = 0.0, s; double angle; int leng;
		if (n == 4 || n == 8 || n == 12 || n == 20||n==6)
		{
			if (n == 4)
				s = sqrt(3)*l*l, angle =PI-acos(1.0 / 3.0);
			else if (n == 8)
				s = 2.0*sqrt(3.0)*l*l, angle = PI-acos(-1.0 / 3.0);
			else if (n == 12)
				s = 12.0*sqrt(25.0 + 10.0*sqrt(5.0)) / 4.0*l*l,angle=PI-acos(-sqrt(5)/5.0);
			else if (n == 20)
				s = 5.0*sqrt(3)*l*l, angle = PI-acos(-sqrt(5) / 3.0);
			else if (n == 6)
				s = 6.0*l*l,angle=PI/2.0;
			leng = ma[n];
			ans += (s*h);
			ans += (PI*h*h*l /(2.0*PI)*angle*leng);
			ans += (4.0 / 3.0*PI*h*h*h);
		}
		else { cout << 0 << endl; continue; }
		printf("%.10f\n", ans);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值