「POJ2451」Uyuw’s Concert
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.
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).
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
1 2 3 4 |
3 10000 10000 0 5000 10000 5000 5000 10000 0 5000 5000 0 |
Sample Output
1 |
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.
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.
求半平面交面积
上模板。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<vector> #define eps 1e-10 using namespace std; double area; int n,top,bot,tot; struct P{double x,y;}a[20005]; struct L{P a,b;double angle;}l[20005],q[20005]; P operator-(P a,P b) { P t;t.x=a.x-b.x;t.y=a.y-b.y;return t; } double operator*(P a,P b) { return a.x*b.y-a.y*b.x; } bool operator<(L a,L b) { if(a.angle==b.angle) return (b.b-a.a)*(b.a-a.a)>0; return a.angle<b.angle; } P inter(L a,L b) { double k1,k2,t; k1=(a.b-b.a)*(b.b-b.a); k2=(b.b-b.a)*(a.a-b.a); t=k1/(k1+k2); P ans; ans.x=a.b.x+(a.a.x-a.b.x)*t; ans.y=a.b.y+(a.a.y-a.b.y)*t; return ans; } bool jud(L a,L b,L t) { P p=inter(a,b); return (t.a-p)*(t.b-p)<0; } void hpi() { sort(l+1,l+n+1); int top=1,bot=0; for(int i=1;i<=n;i++) { if(l[i].angle!=l[i-1].angle)tot++; l[tot]=l[i]; } n=tot;q[0]=l[1];q[1]=l[2]; for(int i=3;i<=n;i++) { while(bot<top&&jud(q[top],q[top-1],l[i]))top--; while(bot<top&&jud(q[bot],q[bot+1],l[i]))bot++; q[++top]=l[i]; } while(bot<top&&jud(q[top],q[top-1],q[bot]))top--; while(bot<top&&jud(q[bot],q[bot+1],q[top]))bot++; q[top+1]=q[bot]; tot=0; for(int i=bot;i<=top;i++) a[++tot]=inter(q[i],q[i+1]); } void getarea() { if(tot<3)return; a[++tot]=a[1]; for(int i=1;i<=tot;i++) area+=a[i]*a[i+1]; area=fabs(area)/2; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lf%lf%lf%lf",&l[i].a.x,&l[i].a.y,&l[i].b.x,&l[i].b.y); } l[++n].a.x=0;l[n].a.y=0;l[n].b.x=10000;l[n].b.y=0; l[++n].a.x=10000;l[n].a.y=0;l[n].b.x=10000;l[n].b.y=10000; l[++n].a.x=10000;l[n].a.y=10000;l[n].b.x=0;l[n].b.y=10000; l[++n].a.x=0;l[n].a.y=10000;l[n].b.x=0;l[n].b.y=0; for(int i=1;i<=n;i++) l[i].angle=atan2((l[i].b.y-l[i].a.y),(l[i].b.x-l[i].a.x)); hpi(); getarea(); printf("%.1lf",area); return 0; } |
黄学长的代码在poj上wa了
膜黄学长,为什么黄学长从不考虑精度却总是能过?
l[i].angle!=l[i-1].angle等没三态函数不是很容易判错吗?
不知道为什么。。。根据我的经验,精度过不了的题,特别是模板题,把eps设成0就能莫名其妙AC QwQ
我基本是有处理精度的吧,这里也不太清楚是怎么回事了
56,57行互换就会错,为啥要先弹栈顶呢??
半平面交这是个坑点
那为什么要先弹栈顶啊。。
不然边界会有问题。。。
噢。。thx黄学长
请问黄学长,边界问题是什么?
YJP
jud和inter是求什么的
好吧,我是傻B,不用管我