程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Aquarium Tank(csu1634+幾何+二分)Contest2087 - 湖南多校對抗賽(2015.05.24)-G

Aquarium Tank(csu1634+幾何+二分)Contest2087 - 湖南多校對抗賽(2015.05.24)-G

編輯:C++入門知識

Aquarium Tank(csu1634+幾何+二分)Contest2087 - 湖南多校對抗賽(2015.05.24)-G


Aquarium Tank

Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 15 Solved: 4
[Submit][Status][Web Board]

Description

You just bought an “artistic” aquarium tank that has an interesting shape, and you poured L litres of water into the tank. How high is the water in the tank?
When you look at this tank from one side, it has the shape of a convex polygon. This polygon has exactly two vertices on the table (y-coordinates are 0), and all other vertices have positive y-coordinates. There are also exactly two vertices with maximum y-coordinates, and water is poured into the opening between these two vertices. This aquarium tank has a depth of D centimetres. The tank is glued to the table, so no matter what shape it has, it keeps its position and does not tip over. All coordinates and lengths in this problem are given in centimetres. It should be noted that each cubic metre is equivalent to 1 000 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 an integer N (4 ≤ N ≤ 100) giving the number of vertices in the polygon. he next line contains two integers D and L, where 1 ≤ D ≤ 1000 is he depth of the aquarium tank and 0  L  2 000 is the number of litres f water to pour into the tank. The next N lines each contains two integers, giving the (x, y) coordinates of the vertices of the convex polygon in counterclockwise order. The absolute values of x and y are at most 1 000. You may assume that the tank has 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
30 50
20 0
100 0
100 40
20 40

Sample Output

20.83

HINT

Source


 

 

題意:有一個橫放是多邊形的稜柱。問L升水,注入其中,容器的深度是多少。

思路:稜柱的體積等於底面積成高,so、、、我可以二分多邊形的高度(用平行與X軸的直線求切割多邊形)取下半部分是面積;

坑!比賽的時候,我以為第一組邊一定是在x軸上的。。。o(︶︿︶)o 唉,結果是一定有一組邊在x軸上,但不一定是第一組!。。。

 

轉載請注明出處:尋找&星空の孩子

題目鏈接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1634

#include
#include
#include
#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.xeps)
        {
            q=0;
            int per=n-1;
            double m=(d+h)/2;
            Point M(0,m);
            Vector w(1,0);
            for(int i=0; ieps)
                {
                    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
****************************************************************/

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved