-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVALive 6532
160 lines (159 loc) · 4.14 KB
/
UVALive 6532
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<complex>
#include<set>
#include<assert.h>
using namespace std;
typedef long long ll;
typedef complex<double> point;
double eps=1e-8;
const double PI=acos(-1.0);
double det(point a,point b){return (conj(a)*b).imag();}
double dot(point a,point b){return (a*conj(b)).real();}
inline int sgn(double n){return abs(n)<eps?0:(n<0?-1:1);}
int cross(point s,point a,point b)
{
point u=a-s;
point v=b-s;
if(sgn(det(u,v))>0) return 1;
if(sgn(det(u,v))<0) return -1;
if(sgn(dot(u,v))<=0) return 0;
if(sgn(abs(u)-abs(v))>0) return 2;
return -2;
}
double Ang;
point O=point(0,0);
struct line: public vector<point>
{
line(){}
line(point a,point b){
push_back(a),push_back(b);
}
};
point vec(line a){return a[1]-a[0];}
point vec(point a){return a/abs(a);}
point InterLL(const line u,const line v)
{
double a=det(vec(u),vec(v));
double b=det(vec(u),u[1]-v[0]);
if(sgn(a)==0) return v[0];
return v[0]+b/a*vec(v);
}
bool operator < (const line& a,const line& b)
{
line t=line(O,point(cos(Ang),sin(Ang)));
return sgn( abs(InterLL(t,a) ) - abs(InterLL(t,b) ) )<0;
}
int S,W,K;
#define MAXN 101000
point kid[MAXN];
line wall[MAXN];
line seg[2*MAXN];
struct node{
int id,kind;
double ang;
node(int _id=0,int _kind=0,double _ang=0):id(_id),kind(_kind),ang(_ang){}
bool operator <(const node &a)const{
if(sgn(ang-a.ang)!=0)
return ang<a.ang;
return kind < a.kind;
}
}event[5*MAXN];
double getAng(point a){ return atan2(a.imag(),a.real());}
int num;
set<line> q;
int solve()
{
int ret=0;
num=0;
for(int i=1;i<K;i++)
{
event[num++]=node(i,1,getAng(kid[i]-kid[0]));
}
for(int i=0;i<W;i++)
{
seg[i]=line(wall[i][0]-kid[0],wall[i][1]-kid[0]);
if(getAng(seg[i][0])>getAng(seg[i][1]))
swap(seg[i][0],seg[i][1]);
int flag=1;
point t=InterLL(seg[i],line(O,point(-1,0)));
if(sgn(abs(getAng(seg[i][0])-getAng(seg[i][1]))-PI)>0)
flag=0;
if(flag)
{
event[num++]=node(i,0,getAng(seg[i][0]));
event[num++]=node(i,2,getAng(seg[i][1]));
}
else{
event[num++]=node(i,0,-PI);
event[num++]=node(i,2,getAng(seg[i][0]));
event[num++]=node(i,0,getAng(seg[i][1]));
event[num++]=node(i,2,PI);
}
}
// for(int i=0;i<k;i++)
// cout<<seg[i][0].real()<<" "<<seg[i][0].imag()<<seg[i][1].real()<<" "<<seg[i][1].imag() <<endl;
// cout<<"******"<<endl;
sort(event,event+num);
// for(int i=0;i<num;i++)
// cout<<event[i].id<<" "<<event[i].kind<<" "<<event[i].ang<<endl;
// cout<<"^^^^^"<<endl;
q.clear();
for(int i=0;i<num;i++)
{
Ang=event[i].ang;
if(event[i].kind==1)
{
if(q.empty() || sgn( abs( InterLL(line(O,point(cos(Ang),sin(Ang))),*q.begin() ) )- abs(kid[event[i].id]-kid[0]) )>0 )
ret++;
}
else{
//printf("****\n");
// if( event[i].kind==0 ) printf(" + %d\n",event[i].id);
// else printf("- %d\n",event[i].id);
if(event[i].kind==0)
q.insert(seg[event[i].id]);
else {
q.erase(seg[event[i].id]);
}
// printf("***\n");
}
// point g;
// cout<<"*****"<<i<<endl;
// g=InterLL(line(point(-20,-10),point(-20,20) ),line(point(0,0) , point(-1,0) ) );
// cout<<"&&&&&"<<endl;
}
return ret;
}
int main()
{
freopen("in.txt","r",stdin);
while(~scanf("%d%d%d",&S,&K,&W))
{
for(int i=0;i<K;i++)
{
double x,y;
scanf("%lf%lf",&x,&y);
kid[i]=point(x,y);
}
for(int i=0;i<W;i++)
{
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
wall[i]=line(point(x1,y1),point(x2,y2));
}
for(int i=0;i<S;i++)
{
swap(kid[0],kid[i]);
printf("%d\n",solve());
}
}
return 0;
}