Aquarium Tank (csu1634+ geometry + dichotomy) Contest2087-Hunan Multi-school Tournament (2015.05.24)-G

Source: Internet
Author: User
Tags acos bool time limit
Aquarium TankTime limit:1 Sec Memory limit:128 MB
Submit:15 Solved:4
[Submit] [Status] [Web Board] Description

You just bought a "artistic" aquarium tank that have an interesting shape, and you poured L litres of water to the tank. How are the water in the tank?
When the "at" tank from one side, it has the shape of a convex polygon. This polygon had exactly, vertices on the table (Y-coordinates is 0), and all other vertices had positive y-coordinat Es. There is also exactly-vertices with maximum y-coordinates, and water was poured into the opening between these both ver Tices. This aquarium tank have a depth of D centimetres. The tank is glued-to-the-table, so-no matter what shape it have, it keeps it position and does not tip over. All coordinates and lengths in this problem is given in centimetres. It should be noted this each cubic metre are equivalent to 1 litres.
An illustration showing the configuration of the tank of the first sample input is given below:

Input

The input consists of a single test case. The first line contains a integer N (4≤n≤100) giving the number of vertices in the polygon. He next line contains-integers D and L, where 1≤d≤1000 is he depth of the aquarium tank and 0 L 2 are the Numbe R of Litres f water to pour into the tank. The next N lines each contains a integers, giving the (x, y) coordinates of the vertices of the convex polygon in Counte Rclockwise order. The absolute values of x and Y is at most 1 000. Assume that the tank have a positive capacity, and you never pour more water than the tank can hold.

Output

Print the height of the water (in centimetres) in the aquarium tank on a line to 2 decimal places.

Sample Input

4
0
0
20 40
Sample Output
20.83
HINT Source



Test Instructions: There is a prism with a polygon in the horizontal place. Ask L to raise the water, into which the depth of the container is how much. Idea: The size of the prism is equal to the bottom area is high, so 、、、 I can split the height of the polygon (using parallel and x-axis straight line to cut the polygon), the half part is the area; Pit. During the game, I thought the first group of sides must be on the X axis ... O (︶^︶) o Alas, the result is that there must be a set of edges on the x-axis, but not necessarily the first group .... reprint please indicate the source: Find & Children of the Star topic Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1634

#include <cstdio> #include <cmath> #include <iostream> #define PI acos ( -1.0) using namespace std;
    struct point {double x, y;
 
Point (Double x=0,double y=0): X (x), Y (y) {}};
Double Hmax;
 
Double d,l;
 
typedef point Vector;
 
Vector operator + (vector a,vector B) {return vector (A.X+B.X,A.Y+B.Y);}
 
Vector operator-(point A,point B) {return Vector (A.X-B.X,A.Y-B.Y);}
 
Vector operator * (vector a,double p) {return vector (a.x*p,a.y*p);}
 
Vector operator/(vector a,double p) {return vector (a.x/p,a.y/p);} BOOL operator < (const point& A,const point& b) {return a.x<b.x| |
(a.x==b.x && a.y<b.y);
 
} Const Double EPS = 1e-8;
    int dcmp (double x) {if (Fabs (x) <eps) return 0; else return x < 0?
-1:1;
 
} bool operator = = (Const point& a,const point& b) {return dcmp (a.x-b.x) ==0 && dcmp (A.Y-B.Y) ==0;} Double Dot (Vector a,vector B) {return a.x*b.x+a.y*b.y;} double Length (vectoR A) {return sqrt (dot (a,a));} double Angle (Vector a,vector B) {return ACOs (dot (b)/length (A)/length (c));} Double Cross (Vector a,vector B) {return a.x*b.y-b.x*a.y,} double Area2 (point a,point b,point C) {return cross (b
-A,C-A);
    } double Parea (point *p,int N) {double area=0;
    for (int i=0; i<n; i++) {Area+=cross (p[i],p[(i+1)%n]);
} return Fabs (AREA/2);
    } point Getlineintersection (Point p,vector v,point q,vector w) {Vector u=p-q;
Return P+v*cross (W,u)/cross (V,W);
    } point Read_point (Point &p) {scanf ("%lf%lf", &p.x,&p.y);
    Hmax=max (HMAX,P.Y);
return P;
    } Point Get_point (Point A, point B, double y0) {if (Fabs (a.x-b.x) < EPS) return point (a.x, y0);
    Double bi = (Y0-A.Y)/(B.Y-A.Y);
Return point (a.x + bi * (b.x-a.x), A.Y + bi * (B.Y-A.Y));
    } int main () {point po[105],q[105];
    int t,n,q,i;
   while (scanf ("%d", &n)!=eof) {scanf ("%lf%lf", &d,&l);     hmax=0;
        for (i=0; i<n; i++) {read_point (po[i]);
        } double D=0,h=hmax;
            while (h-d>eps) {q=0;
            int per=n-1;
            Double m= (d+h)/2;
            Point M (0,M);
            Vector W (1,0);
                    for (int i=0; i<n; i++) {if (m-po[i].y) * (M-PO[PER].Y) <eps) {
                    Vector Pp=po[i]-po[per];
                    Q[q++]=getlineintersection (PO[PER],PP,M,W);
                Q[q++]=get_point (PO[I],PO[PER],M);
                } if ((M-PO[I].Y) >eps) {q[q++]=po[i];
            } per=i;
            } double Area=parea (Q,Q);
            if (l*1000-area*d>eps) d=m;
        else h=m;
    } printf ("%.2f\n", D);
} return 0; }/************************************************************** problem:1634 user:aking2015 language:c++ result:accepted time:0 Ms memory:1500 KB ************************************************ ****************/


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.