ZOJ 3913 Bob wants to pour water (计算几何+二分)

题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3913

题意:有一个无穷高的长方体,里面有一些球和小的长方体,然后往大的长方体里面倒水,水只能填充到间隙里面,问水能填多高。  告诉的有 ,水的体积,大的长方体的长和宽,以及每个小的长方体的中心的高度,及它的长宽高,和球的中心的高度以及球的半径。

Bob wants to pour water

Time Limit: 2 Seconds       Memory Limit: 65536 KB       Special Judge

There is a huge cubiod house with infinite height. And there are some spheres and some cuboids in the house. They do not intersect with others and the house. The space inside the house and outside the cuboids and the spheres can contain water.

Bob wants to know when he pours some water into this house, what's the height of the water level based on the house's undersurface.

Input

The first line is a integer T (1 ≤ T ≤ 50), the number of cases.

For each case:

The first line contains 3 floats wl (0 < wl < 100000), the width and length of the house, v (0 < v < 1013), the volume of the poured water, and 2 integers, m (1 ≤ m ≤ 100000), the number of the cuboids, n (1 ≤ n ≤ 100000), the number of the spheres.

The next m lines describe the position and the size of the cuboids.

Each line contains z (0 < z < 100000), the height of the center of each cuboid, a (0 < a < w), b (0 < b < l), c, the width, length, height of each cuboid.

The next n lines describe the position and the size of the spheres, all these numbers are double.

Each line contains z (0 < z < 100000), the height of the center of each sphere, r (0 < 2r < w and 2r < l), the radius of each sphere.

Output

For each case, output the height of the water level in a single line. An answer with absolute error less than 1e-4 or relative error less than 1e-6 will be accepted. There're T lines in total.

Sample Input
1
1 1 1 1 1
1.5 0.2 0.3 0.4
0.5 0.5
Sample Output
1.537869
 
 
已知:球半径R,球缺高H。我们就可以得到球缺的体积为:
V=πH^2(R-H/3)
二分答案就好了。

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn = 1e5+6;
const double PI = acos(-1.0);
struct sphere
{
	double z,r;
}s[maxn];
struct cuboids
{
	double z,l,w,h;
}c[maxn];

int n,m;
double w,l,v;

double cal(double h)
{
	int i,j;
	double ret=0;
	for(i=1;i<=m;i++)
	{
		if(h<=c[i].z-c[i].h/2.0)
			continue ;
		if(h>=c[i].z+c[i].h/2.0)
		{
			ret+=c[i].l*c[i].w*c[i].h;
			continue ;
		}
		if(h>=c[i].z)
		{
			ret+=(c[i].l*c[i].w*c[i].h)/2.0;
			ret+=(c[i].l*c[i].w*(h-c[i].z));
			continue ;
		}
		else
		{
			ret+=(c[i].l*c[i].w*(c[i].h/2.0-(c[i].z-h)));
			continue ;
		}
	}
	for(i=1;i<=n;i++)
	{
		if(h<=s[i].z-s[i].r)
			continue ;
		if(h>=s[i].z+s[i].r)
		{
			ret+=4/3.0*PI*s[i].r*s[i].r*s[i].r;
			continue ;
		}
		double H;
		if(h>=s[i].z)
			H=s[i].r+h-s[i].z;
		else
			H=s[i].r-(s[i].z-h);
		ret+=PI*H*H*(s[i].r-H/3.0);
	}
	return l*w*h-ret;
}

double Find()
{
	double down=0,mid,up=1000000;
	while(up-down>=0.0000001)
	{
		mid=(down+up)/2.0;
		if(v<cal(mid))
			up=mid;
		else
			down=mid;
	}
	return mid;
}

int main()
{
	int ncase,i,j;
	scanf("%d",&ncase);
	while(ncase--)
	{
		scanf("%lf%lf%lf%d%d",&w,&l,&v,&m,&n);
		for(i=1;i<=m;i++)
			scanf("%lf%lf%lf%lf",&c[i].z,&c[i].l,&c[i].w,&c[i].h);
		for(i=1;i<=n;i++)
			scanf("%lf%lf",&s[i].z,&s[i].r);
		printf("%.6lf\n",Find());
	}
	return 0;
}


基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip基于bert实现关系三元组抽取python源码+数据集+项目说明.zip 个人大四的毕业设计、课程设计、作业、经导师指导并认可通过的高分设计项目,评审平均分达96.5分。主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。 [资源说明] 不懂运行,下载完可以私聊问,可远程教学 该资源内项目源码是个人的毕设或者课设、作业,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96.5分,放心下载使用! 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),供学习参考。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值