UVA 11355 Cool Points( 极角计算 )

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 x1y1x2 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%

 

 

 

题意就是给出一个圆 , 还有一些线段( 不过圆心 )

问在圆上的点与圆心的连线没有交点的点占总点数的百分比。

那么就将所有线段的两个端点都弄成极角。然后排个序。

如果线段的两个端点极角分别跨越正负的话,就将它处理成两条线段 。 

再处理一下区间 , 求百分比就能过了。

 

#include<bits/stdc++.h>
using namespace std;
const int N = 205;
const double PI = acos(-1.0);
const double eps = 1e-6;
typedef pair<double,double> pii;
#define X first
#define Y second
int n , top ;
vector<pii>p;
double x[N] , y[N];

int dcmp( double x ) {
    if( fabs(x) < eps ) return 0 ;
    return x<0?-1:1;
}

double cal( double avg1 , double avg2 ) {
    if( avg1 < 0 && avg2 < 0 ) return -1.0 ;
    if( avg1 > 0 && avg2 > 0 ) return -1.0 ;
    return fabs( avg1 ) + fabs( avg2 ) ;
}
void Solve() {
    top = 0 ;
    for( int i = 0 ; i < p.size() ; ++i ){
        while( top > 0 && dcmp( p[i].X-x[top-1])==0 && dcmp(p[i].Y-y[top-1])>=0 )top--;
        if( top > 0 && dcmp(x[top-1]-p[i].X)<=0 && dcmp(y[top-1]-p[i].Y)>=0 )continue ;
        x[top] = p[i].X , y[top] = p[i].Y , top++;
    }
}
void Run() {
    double x1 , y1 , x2 , y2 , r ;
    scanf("%d%lf",&n,&r); p.clear();
    if( !n ) { puts("100.00%"); return ; }
    for( int i = 0 ; i < n ; ++i ){
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
        double avg1 = atan2(y1,x1) , avg2 = atan2(y2,x2) ;
        if( avg1 > avg2 ) swap( avg1 , avg2 );
        double d = cal( avg1 , avg2 );
        if( d == -1.0 ) { p.push_back(pii(avg1,avg2)); continue; }
        if( d < PI ) {
            p.push_back(pii(avg1,0));
            p.push_back(pii(0,avg2));
        }
        else {
            p.push_back(pii(-PI,avg1));
            p.push_back(pii(avg2,PI));
        }
    }
    sort( p.begin() , p.end() );
    Solve();
    double s = x[0] , e = y[0] , fenzi = 0 ;
    for( int i = 1 ; i < top ; ++i ){
        if( x[i] > e ) {
            fenzi += ( e - s ); s = x[i];
        }
        e = y[i] ;
    }
    fenzi += ( e - s );
    double ans = 100.0 - fenzi/(2.0*PI)*100.0;
    printf("%.2lf",ans);puts("%");
}

int main() {
//    freopen("in.txt","r",stdin);
    int _ , cas = 1 ;
    scanf("%d",&_); while( _ -- ) {
        printf("Case %d: ",cas++);
        Run();
    }
}
View Code

 

转载于:https://www.cnblogs.com/hlmark/p/4173646.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值