POJ 2451: Uyuw's Concert 半平面交
2018-02-13 14:32
597 查看
Uyuw's Concert
DescriptionPrince 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?InputIn 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).OutputOutput a single floating number, rounded to 1 digit after the decimal point. This is the maximal area of the stage.Sample Input3
10000 10000 0 5000
10000 5000 5000 10000
0 5000 5000 0
Sample Output54166666.7HintSample 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.
SourcePOJ Monthly,Zeyuan Zhu
求多边形核的面积
狂WA不止 不止
对着一份卵问题都没有的code调了整整三天
我已经是个废人了
记得 输出不要用 %lf 用 %f 啊啊啊啊
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef double db;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}
const int N=20100;
const db eps=1e-10;
struct point
{
db x,y;
friend point operator +(const point &a,const point &b)
{return (point){a.x+b.x,a.y+b.y};}
friend point operator -(const point &a,const point &b)
{return (point){a.x-b.x,a.y-b.y};}
friend db cross(const point &x,const point &y,const point &bas)
{
point a(x-bas),b(y-bas);
return a.x*b.y-a.y*b.x;
}
}p
;
int scnt;
struct segment
{
point X,Y;db angle;
friend bool operator <(const segment &a,const segment &b)
{
if(fabs(a.angle-b.angle)<eps) return cross(a.Y,a.X,b.X)>0;
return a.angle<b.angle;
}
friend point get_node(const segment &a,const segment &b)
{
point res;db s[2];
s[0]=cross(a.Y,a.X,b.X);
s[1]=cross(a.X,a.Y,b.Y);
res.x=(b.Y.x*s[0]+b.X.x*s[1])/(s[0]+s[1]);
res.y=(b.Y.y*s[0]+b.X.y*s[1])/(s[0]+s[1]);
return res;
}
friend bool check(const segment &a,const segment &b,const segment &c)
{
point tmp(get_node(a,b));
return cross(c.X,c.Y,tmp)<-eps;
}
}seg
;
inline void add_seg(const point &a,const point &b)
{
seg[++scnt].X=a,seg[scnt].Y=b;
seg[scnt].angle=atan2(b.y-a.y,b.x-a.x);
}
int top,q[N<<1];
point st
;
void hpi()
{
sort(seg+1,seg+1+scnt);
register int i,tot(1),head(0),tail(2);
for(i=2;i<=scnt;++i)
if(seg[i].angle-seg[tot].angle>eps)
seg[++tot]=seg[i];
q[0]=1,q[1]=2;
for(i=3;i<=tot;++i)
{
while(head<tail-1 && check(seg[q[tail-1]],seg[q[tail-2]],seg[i])) tail--;
while(head<tail-1 && check(seg[q[head]],seg[q[head+1]],seg[i])) head++;
q[tail++]=i;
}
while(head<tail-1 && check(seg[q[tail-1]],seg[q[tail-2]],seg[q[head]])) tail--;
while(head<tail-1 && check(seg[q[head]],seg[q[head+1]],seg[q[tail-1]])) head++;
q[tail]=q[head];
for(i=head+1;i<=tail;++i)
st[++top]=get_node(seg[q[i-1]],seg[q[i]]);
}
db S=0;
void get_S()
{
register int i;
for(i=2;i<top;++i)
S+=cross(st[i],st[i+1],st[1]);
S=fabs(S/2.0);
}
int main()
{
int n=read();
register int i;
point u,v;
for(i=1;i<=n;++i)
scanf("%lf%lf%lf%lf",&u.x,&u.y,&v.x,&v.y),
add_seg(u,v);
u=(point){0,0};v=(point){10000,0}; add_seg(u,v);
u=v;v=(point){10000,10000}; add_seg(u,v);
u=v;v=(point){0,10000}; add_seg(u,v);
u=v;v=(point){0,0}; add_seg(u,v);
hpi();get_S();
printf("%.1f\n",S);
return 0;
}
Time Limit: 6000MS | Memory Limit: 65536K | |
Total Submissions: 10717 | Accepted: 3885 |
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?InputIn 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).OutputOutput a single floating number, rounded to 1 digit after the decimal point. This is the maximal area of the stage.Sample Input3
10000 10000 0 5000
10000 5000 5000 10000
0 5000 5000 0
Sample Output54166666.7HintSample 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.
SourcePOJ Monthly,Zeyuan Zhu
求多边形核的面积
狂WA不止 不止
对着一份卵问题都没有的code调了整整三天
我已经是个废人了
记得 输出不要用 %lf 用 %f 啊啊啊啊
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef double db;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}
const int N=20100;
const db eps=1e-10;
struct point
{
db x,y;
friend point operator +(const point &a,const point &b)
{return (point){a.x+b.x,a.y+b.y};}
friend point operator -(const point &a,const point &b)
{return (point){a.x-b.x,a.y-b.y};}
friend db cross(const point &x,const point &y,const point &bas)
{
point a(x-bas),b(y-bas);
return a.x*b.y-a.y*b.x;
}
}p
;
int scnt;
struct segment
{
point X,Y;db angle;
friend bool operator <(const segment &a,const segment &b)
{
if(fabs(a.angle-b.angle)<eps) return cross(a.Y,a.X,b.X)>0;
return a.angle<b.angle;
}
friend point get_node(const segment &a,const segment &b)
{
point res;db s[2];
s[0]=cross(a.Y,a.X,b.X);
s[1]=cross(a.X,a.Y,b.Y);
res.x=(b.Y.x*s[0]+b.X.x*s[1])/(s[0]+s[1]);
res.y=(b.Y.y*s[0]+b.X.y*s[1])/(s[0]+s[1]);
return res;
}
friend bool check(const segment &a,const segment &b,const segment &c)
{
point tmp(get_node(a,b));
return cross(c.X,c.Y,tmp)<-eps;
}
}seg
;
inline void add_seg(const point &a,const point &b)
{
seg[++scnt].X=a,seg[scnt].Y=b;
seg[scnt].angle=atan2(b.y-a.y,b.x-a.x);
}
int top,q[N<<1];
point st
;
void hpi()
{
sort(seg+1,seg+1+scnt);
register int i,tot(1),head(0),tail(2);
for(i=2;i<=scnt;++i)
if(seg[i].angle-seg[tot].angle>eps)
seg[++tot]=seg[i];
q[0]=1,q[1]=2;
for(i=3;i<=tot;++i)
{
while(head<tail-1 && check(seg[q[tail-1]],seg[q[tail-2]],seg[i])) tail--;
while(head<tail-1 && check(seg[q[head]],seg[q[head+1]],seg[i])) head++;
q[tail++]=i;
}
while(head<tail-1 && check(seg[q[tail-1]],seg[q[tail-2]],seg[q[head]])) tail--;
while(head<tail-1 && check(seg[q[head]],seg[q[head+1]],seg[q[tail-1]])) head++;
q[tail]=q[head];
for(i=head+1;i<=tail;++i)
st[++top]=get_node(seg[q[i-1]],seg[q[i]]);
}
db S=0;
void get_S()
{
register int i;
for(i=2;i<top;++i)
S+=cross(st[i],st[i+1],st[1]);
S=fabs(S/2.0);
}
int main()
{
int n=read();
register int i;
point u,v;
for(i=1;i<=n;++i)
scanf("%lf%lf%lf%lf",&u.x,&u.y,&v.x,&v.y),
add_seg(u,v);
u=(point){0,0};v=(point){10000,0}; add_seg(u,v);
u=v;v=(point){10000,10000}; add_seg(u,v);
u=v;v=(point){0,10000}; add_seg(u,v);
u=v;v=(point){0,0}; add_seg(u,v);
hpi();get_S();
printf("%.1f\n",S);
return 0;
}
相关文章推荐
- POJ 2451 Uyuw's Concert(半平面交,求面积,裸)
- poj 2451 Uyuw's Concert - 半平面交
- poj2451 Uyuw's Concert【半平面交】
- POJ 2451 Uyuw's Concert (半平面交)
- POJ 2451 Uyuw's Concert(半平面交)
- poj 2451 Uyuw's Concert(半平面交求面积)
- poj 2451 Uyuw's Concert (半平面交)
- POJ 2451 Uyuw's Concert(半平面交求面积)
- POJ 2451 Uyuw's Concert 半平面交求面积
- POJ 2451 Uyuw's Concert
- poj 2451 Uyuw's Concert
- POJ 2451 Uyuw's Concert
- poj 2451 Uyuw's Concert(半平面交)
- POJ 2451 Uyuw's Concert
- POJ 2451 Uyuw's Concert
- POJ 2451 Uyuw's Concert 题解
- 【Poj 2451】Uyuw's Concert
- POJ2451-Uyuw's Concert
- POJ 2451 Uyuw's Concert(半平面交nlgn)
- poj 2451 Uyuw's Concert (半平面交)