UVA 11355 Cool Points( 極角計算 )

來源:互聯網
上載者:User

標籤:

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%

 

 

 

題意就是給出一個圓 , 還有一些線段( 不過圓心 )

問在圓上的點與圓心的連線沒有交點的點佔總點數的百分比。

那麼就將所有線段的兩個端點都弄成極角。然後排個序。

如果線段的兩個端點極角分別跨越正負的話,就將它處理成兩條線段 。 

再處理一下區間 , 求百分比就能過了。

 

#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 secondint 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

 

UVA 11355 Cool Points( 極角計算 )

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.