(二分,数学积分)icpc2015,D.Cutting Cheese

来源:互联网 发布:mysql全国地区数据库 编辑:程序博客网 时间:2024/05/28 23:20

Cutting Cheese

Problem ID: cheeseTime limit: 7 secondsMemory limit: 1024 MB

DIFFICULTY

1.5
/problemimage?problem=cheese&img=/en/img-0001.jpg
Picture by Jon Sullivan via Wikimedia Commons
Of course you have all heard of the International Cheese Processing Company. Their machine for cutting a piece of cheese into slices of exactly the same thickness is a classic. Recently they produced a machine able to cut a spherical cheese (such as Edam) into slices – no, not all of the same thickness, but all of the same weight! But new challenges lie ahead: cutting Swiss cheese.

Swiss cheese such as Emmentaler has holes in it, and the holes may have different sizes. A slice with holes contains less cheese and has a lower weight than a slice without holes. So here is the challenge: cut a cheese with holes in it into slices of equal weight.

By smart sonar techniques (the same techniques used to scan unborn babies and oil fields), it is possible to locate the holes in the cheese up to micrometer precision. For the present problem you may assume that the holes are perfect spheres.

Each uncut block has size 100×100×100 where each dimension is measured in millimeters. Your task is to cut it into s slices of equal weight. The slices will be 100 mm wide and 100 mm high, and your job is to determine the thickness of each slice.

Input

The first line of the input contains two integers n and s, where 0n10000 is the number of holes in the cheese, and 1s100 is the number of slices to cut. The next n lines each contain four positive integers rxy, and zthat describe a hole, where r is the radius and xy, and z are the coordinates of the center, all in micrometers.

The cheese block occupies the points (x,y,z) where 0x,y,z100000, except for the points that are part of some hole. The cuts are made perpendicular to the z axis.

You may assume that holes do not overlap but may touch, and that the holes are fully contained in the cheese but may touch its boundary.

Output

Display the s slice thicknesses in millimeters, starting from the end of the cheese with z=0. Your output should have an absolute or relative error of at most 106.

Sample Input 1Sample Output 1
0 4
25.00000000025.00000000025.00000000025.000000000
Sample Input 2Sample Output 2
2 510000 10000 20000 2000040000 40000 50000 60000
14.61110314216.26980173424.09245778827.00299227218.023645064

/*题目:Cutting Cheese链接:https://icpc.kattis.com/problems/cheese题意:有一个100*100*100的奶酪,里面有n个不相交的圆孔,问要切成k层,每一层需要分别为多厚?分析:二分,数学积分。1.用积分求不完整圆孔的体积。2.二分查找质量为相应质量的奶酪对应的高度,则易求得答案。*/#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 10005;const double pai = acos(-1);const double EPS = 1e-8;typedef long long LL;const int INF = 0xfffffff;int input(){int a;scanf("%d", &a);return a;}/*-------------------------------------------*/const double daf = 100;int N, S;struct NODE{double r, x, y, z;}a[maxn];vector<double> ans;/********************************************/double area(double r){return 4.0 / 3 * pai*r*r*r;}double cal(double R, double H){return 1.0 / 3 *pai* (2.0*R*R*R - 3.0*R*R*H + H*H*H);}double Judge(double hori){double sum = daf * daf * hori;for (int i = 0; i<N; i++)//对每一个圆{if (a[i].z - a[i].r >= hori)continue;//完全在hori之上else if (a[i].z + a[i].r <= hori)//完全在hori之下{sum -= area(a[i].r);}else if (a[i].z>=hori&&hori >= a[i].z - a[i].r)//下半部分在hori之下{sum -= cal(a[i].r,a[i].z - hori);}else if (a[i].z+a[i].r>=hori&&hori >= a[i].z)//上半部分在hori之上{sum -= (area(a[i].r) - cal(a[i].r, hori-a[i].z));}}return sum;}void solve(double des){double l = 0, u = daf;while (fabs(u - l) > EPS){double mid = (l + u) / 2;if (Judge(mid) > des)u = mid;elsel = mid;}ans.push_back((l + u) / 2);}/********************************************/int main(){//#ifdef LOCAL_JUDGE//freopen("f:\\input.txt", "r", stdin);//#endifwhile (~scanf("%d%d", &N, &S)){double sum = daf * daf * daf;for (int i = 0; i < N; i++){scanf("%lf%lf%lf%lf", &a[i].r, &a[i].x, &a[i].y, &a[i].z);a[i].r /= 1000;a[i].x /= 1000;a[i].y /= 1000;a[i].z /= 1000;sum -= area(a[i].r);}double per = sum / S;ans.clear();ans.push_back(0);for (int i = 1; i <= S-1; i++){solve(per*i);}ans.push_back(100);for (int i = 1; i < ans.size(); i++){printf("%.9f\n", ans[i] - ans[i - 1]);}}return 0;}



0 0
原创粉丝点击