zoukankan      html  css  js  c++  java
  • poj 2451 Uyuw's Concert(半平面交)

    Uyuw's Concert
    Time Limit: 6000MS   Memory Limit: 65536K
    Total Submissions: 8580   Accepted: 3227

    Description

    Prince Remmarguts solved the CHESS puzzle successfully. As an award, Uyuw planned to hold a concert in a huge piazza named after its great designer Ihsnayish.

    The piazza in UDF - United Delta of Freedom’s downtown was a square of [0, 10000] * [0, 10000]. Some basket chairs had been standing there for years, but in a terrible mess. Look at the following graph.

    In this case we have three chairs, and the audiences face the direction as what arrows have pointed out. The chairs were old-aged and too heavy to be moved. Princess Remmarguts told the piazza's current owner Mr. UW, to build a large stage inside it. The stage must be as large as possible, but he should also make sure the audience in every position of every chair would be able to see the stage without turning aside (that means the stage is in the forward direction of their own).

    To make it simple, the stage could be set highly enough to make sure even thousands of chairs were in front of you, as long as you were facing the stage, you would be able to see the singer / pianist – Uyuw.

    Being a mad idolater, can you tell them the maximal size of the stage?

    Input

    In the first line, there's a single non-negative integer N (N <= 20000), denoting the number of basket chairs. Each of the following lines contains four floating numbers x1, y1, x2, y2, which means there’s a basket chair on the line segment of (x1, y1) – (x2, y2), and facing to its LEFT (That a point (x, y) is at the LEFT side of this segment means that (x – x1) * (y – y2) – (x – x2) * (y – y1) >= 0).

    Output

    Output a single floating number, rounded to 1 digit after the decimal point. This is the maximal area of the stage.

    Sample Input

    3
    10000 10000 0 5000
    10000 5000 5000 10000
    0 5000 5000 0
    

    Sample Output

    54166666.7

    Hint

    Sample input is the same as the graph above, while the correct solution for it is as below:

    I suggest that you use Extended in pascal and long double in C / C++ to avoid precision error. But the standard program only uses double.

    Source

    POJ Monthly,Zeyuan Zhu

    【思路】

           半平面交。

           注意设置边界,输入向量方向和eps选择,1e-10足够。

    【代码】

     1 #include<cmath>
     2 #include<cstdio>
     3 #include<vector>
     4 #include<cstring>
     5 #include<algorithm>
     6 #define FOR(a,b,c) for(int a=(b);a<=(c);a++)
     7 using namespace std;
     8 
     9 const int eps = 1e-10;
    10 
    11 struct Pt {
    12     double x,y;
    13     Pt (double x=0,double y=0) :x(x),y(y) {}
    14 };
    15 typedef Pt vec;
    16 
    17 vec operator - (Pt a,Pt b) { return vec(a.x-b.x,a.y-b.y); }
    18 vec operator + (vec a,vec b) { return vec(a.x+b.x,a.y+b.y); }
    19 vec operator * (vec a,double x) { return vec(a.x*x,a.y*x); }
    20 
    21 double cross(Pt a,Pt b) { return a.x*b.y-a.y*b.x; }
    22 
    23 struct Line {
    24     Pt p; vec v; double ang;
    25     Line() {}
    26     Line(Pt p,vec v) :p(p),v(v) { ang=atan2(v.y,v.x); }
    27     bool operator < (const Line& rhs) const {
    28         return ang < rhs.ang;
    29     }
    30 };
    31 //p在l的左边
    32 bool onleft(Line L,Pt p) { return cross(L.v,p-L.p)>0; }
    33 Pt getLineInter(Line a,Line b) {
    34     vec u=a.p-b.p;
    35     double t=cross(b.v,u)/cross(a.v,b.v);
    36     return a.p+a.v*t;
    37 }
    38 
    39 vector<Pt> HPI(vector<Line> L) {
    40     int n=L.size();
    41     sort(L.begin(),L.end());
    42     int f,r;
    43     vector<Pt> p(n) , ans;
    44     vector<Line> q(n);
    45     q[f=r=0]=L[0];
    46     for(int i=1;i<n;i++) {
    47         while(f<r && !onleft(L[i],p[r-1])) r--;
    48         while(f<r && !onleft(L[i],p[f])) f++;
    49         q[++r]=L[i];
    50         if(fabs(cross(q[r].v,q[r-1].v))<eps) {
    51             r--;
    52             if(onleft(q[r],L[i].p)) q[r]=L[i];
    53         }
    54         if(f<r) p[r-1]=getLineInter(q[r-1],q[r]);
    55     }
    56     while(f<r && !onleft(q[f],p[r-1])) r--;
    57     if(r-f<=1) return ans;
    58     p[r]=getLineInter(q[r],q[f]);
    59     for(int i=f;i<=r;i++) ans.push_back(p[i]);
    60     return ans;
    61 }
    62 vector<Line> L;
    63 vector<Pt> p;
    64 int n;
    65 
    66 int main() {
    67     //freopen("in.in","r",stdin);
    68     //freopen("out.out","w",stdout);
    69     scanf("%d",&n);
    70     double x1,y1,x2,y2;
    71     for(int i=0;i<n;i++) {
    72         scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    73         Pt a(x1,y1) , b(x2,y2);
    74         L.push_back(Line(a,b-a));
    75     }
    76     Pt a(0,0),b(10000,0),c(10000,10000),d(0,10000);
    77     L.push_back(Line(a,b-a));
    78     L.push_back(Line(b,c-b));
    79     L.push_back(Line(c,d-c));
    80     L.push_back(Line(d,a-d));
    81     p = HPI(L);
    82     double ans=0; int m=p.size();
    83     for(int i=1;i<m-1;i++)
    84         ans += cross(p[i]-p[0],p[i+1]-p[0]);
    85     printf("%.1lf",ans/2);
    86     return 0;
    87 }
  • 相关阅读:
    [51单片机] TFT2.4彩屏1 [文字显示 画矩形]
    [51单片机] 中断1-中断整体介绍
    [汇编] 从键盘输入一个一位数字,然后响铃n声
    [汇编] 比较2个字符串是否相等
    [汇编] 将字符串里的一个'&'字符换成空格
    [汇编] 2数相加极简单版
    mysql的IFNULL函数
    mysql 中 unix_timestamp和from_unixtime函数
    Excel实现二级菜单联动
    Hibernate中@Embedded和@Embeddable注解
  • 原文地址:https://www.cnblogs.com/lidaxin/p/5183958.html
Copyright © 2011-2022 走看看