Zoj 3913 Bob wants to pour water (two points) __zoj

Source: Internet
Author: User

Topic Link:

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

The main effect of the topic:

In a house with a long width and a height of l,w,h, there are some cubes and balls. Now pour the V-liter into the house. Some cubes and balls float and some sink under the water. Now that we know the center height of each cube and ball, ask the height of the water level in the room.

Ideas:

Two points.

You can divide the height of the water level in the room and then calculate the volume of the cubes and balls in the water, and then compare the total volume in the room with the volume of water poured into the water after the cube and the ball are submerged. If it is equal, it is the height of the request.

Here is a request: a sphere to intercept part of the volume v=π*b^2* (R-B/3). b is the distance from the spherical surface after interception.

Code:

#include <stdio.h> #include <string.h> #include <math.h> #define PI acos ( -1.0) #define EPS 0.0000000001 struct node{double z,a,b,c;}
P[100005]; struct node1{double z,r;}
Q[100005];
Double w,len,v;
int n,m;
    Double cal (double x) {int i,j;
    Double ans=0;
        for (i=1;i<=m;i++) {if (x>=p[i].z+p[i].c/2.0) ans=ans+p[i].a*p[i].b*p[i].c;
        else if (x<=p[i].z-p[i].c/2.0) ans=ans+0;

    else ans=ans+p[i].a*p[i].b* (x (p[i].z-p[i].c/2.0));
        for (i=1;i<=n;i++) {if (X&GT;=Q[I].Z+Q[I].R) ANS=ANS+4.0/3*PI*Q[I].R*Q[I].R*Q[I].R;
        else if (X&LT;=Q[I].Z-Q[I].R) ans=ans+0; else if (x>q[i].z-q[i].r&&x<q[i].z) ans=ans+pi* (q[i].r+x-q[i].z) * (q[i].r+x-q[i].z) * (q[i].r-(q[i].r+
        X-Q[I].Z)/3.0); else ans=ans+4.0/3*pi*q[i].r*q[i].r*q[i].r-pi* (q[i].r+q[i].z-x) * (q[i].r+q[i].z-x) * (q[i].r-(Q[I].R+Q[I].Z-X)/3.0
    );
return ans;
    Double Erfen (double l,double r) {double Mid,mianji; while (Fabs (l-r) &Gt;eps) {mid= (l+r)/2.0;
        Double X=cal (mid);
        Mianji=w*len*mid-x;
        if (Fabs (mianji-v) <=eps) return mid;
        else if (mianji<v) L=mid;
    else if (mianji>v) R=mid;
return mid;
  int main () {int t,i,j,k;
    printf ("%.9f\n", PI);
    scanf ("%d", &t);
        while (t--) {scanf ("%lf%lf%lf%d%d", &w,&len,&v,&m,&n);
        for (i=1;i<=m;i++) scanf ("%lf%lf%lf%lf", &p[i].z,&p[i].a,&p[i].b,&p[i].c);
        for (i=1;i<=n;i++) scanf ("%lf%lf", &AMP;Q[I].Z,&AMP;Q[I].R);
        Double Ans=erfen (0,10000000000005);
    printf ("%.8f\n", ans);
return 0;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.