We have a circle of radius R and several line segments situated within the circumference of this circle. Let’s define a cool point to be a point on the circumference of this circle so that the line segment that is formed by this point and the centre of the circle makes no intersection with any of the given line segments.
For this problem, you have to find out the percentage of cool points from all possible points on the circumference of the given circle.
Input
The input file starts with an integer T(T<1000) that indicates the number of test cases. Each case starts with 2 integers N(0 <= N < 100) and R(0 < R < 1001). N represents the number of line segments and R represents the radius of the circle. Each of the next N lines contains 4 integers in the order x1, y1,x2 and y2. (x1, y1) – (x2, y2) represents a line segment.
You can assume that all the line segments will be inside the circle and no line segment passes through the origin. Also consider the center of the circle to be on the origin.
Output
For each input, output the case number followed by the percentage, rounded to 2 decimal places, of cool points. Look at the output for exact format.
Sample Input
Output for Sample Input
2
1 10
2 0 0 2
0 5
Case 1: 75.00%
Case 2: 100.00%
view code#include <bits/stdc++.h> using namespace std; double PI = acos(-1.0); int _, cas=1, n, r; struct event { double x; int y; bool operator < (const event &o) const{ return x<o.x; } event() {} event(double x, int y):x(x),y(y) {} }e[4321]; int ecnt; void addseg(double a, double b) { if(a>b) swap(a,b); e[ecnt++] = event(a, 1); e[ecnt++] = event(b, -1); } int main() { // freopen("in.txt", "r", stdin); cin>>_; while(_--) { scanf("%d%d", &n, &r); ecnt = 0; double a,b,c,d; for(int i=0; i<n; i++) { scanf("%lf%lf%lf%lf", &a, &b, &c, &d); double x = atan2(b,a), y = atan2(d,c); if(x<y) swap(x, y); if(x-y>PI) { addseg(-PI, y); addseg(x, PI); } else addseg(x, y); } int eventnum = 0; sort(e, e+ecnt); double last = -PI, ans = 0.0; for(int i=0; i<ecnt; i++) { if(eventnum==0)//这里很经典,记下 { ans += e[i].x - last; } eventnum += e[i].y; last = e[i].x; } ans += PI - last; printf("Case %d: %.2f%%\n", cas++, (ans/(PI*2)*100)); } return 0; }
UVA 11355 Cool Points