• 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
    only strive for your goal , can you make your dream come true ?
  • 相关阅读:
    【ST开发板评测】Nucleo-F411RE开箱报告
    手把手教你制作Jlink-OB调试器(含原理图、PCB、外壳、固件)
    国产处理器的逆袭机会——RISC-V
    基于uFUN开发板和扩展板的联网校准时钟
    基于uFUN开发板的RGB调色板
    理解ffmpeg中的pts,dts,time_base
    如何终止线程的运行(C/C++)
    关于阻塞和非阻塞,同步和异步的总结
    QT移植无法启动 This application failed to start because it could not find or load the QT platform
    Qt5学习记录:QString与int值互相转换
  • 原文地址:https://www.cnblogs.com/hlmark/p/4173646.html
Copyright © 2020-2023  润新知