http://acm.fzu.edu.cn/problem.php?pid=19182010福州邀请赛 J 题
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<complex>
using namespace std;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
typedef complex<double> point;
const int maxn = 80010;
const double pi = acos( -1.0 );
const double eps = 1e-8;
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
//struct poly
//{
// point p[maxn];
// int n;
//};
//poly P[11];
struct node
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
double x1, x2;
bool operator<( const node & b )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
return x1 < b.x1;
}
};
node a[maxn*10];
point dir[4];
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) double operator^( point p1, point p2 ) { return imag( conj( p1 ) * p2 ); }
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) double operator&( point p1, point p2 ) { return real( conj( p1 ) * p2 ); }
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) int dblcmp( double x ) { return ( x < -eps ? - 1 : x > eps ); }
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int main( )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int t, n, i, j, polynum, len, d, k = 1;
point Q, S, s, e;
char c[3];
double x, y, sita1, sita2, total;
dir[0] = point( 0.0, 1.0 ); dir[1] = point( -1.0, 0.0 );
dir[2] = point( 0.0, -1.0 ); dir[3] = point( 1.0, 0.0 );
scanf("%d",&t);
while( t-- )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf("%d%lf%lf",&polynum,&x,&y);
Q = point( x, y );
len = 0;
for( i = 0; i < polynum; i++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf("%d%lf%lf",&n,&x,&y);
s = point( x, y );
d = 0;
for( j = 0; j < n; j++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf("%s",c);
switch( c[0] )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
case 'F':
scanf("%lf",&x);
e = s + x * dir[d];
if( dblcmp( s - Q ^ e - Q ) != 0 )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
sita1 = arg( e - Q );
sita2 = arg( s - Q );
if( sita1 < sita2 )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if( !( sita1 < -pi / 2.0 && sita2 > pi / 2.0 ) )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
a[len].x1 = sita1;
a[len++].x2 = sita2;
}
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
a[len].x1 = -pi;
a[len++].x2 = sita1;
a[len].x1 = sita2;
a[len++].x2 = pi;
}
}
else if( sita2 < sita1 )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if( !( sita2 < -pi / 2.0 && sita1 > pi / 2.0 ) )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
a[len].x1 = sita2;
a[len++].x2 = sita1;
}
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
a[len].x1 = -pi;
a[len++].x2 = sita2;
a[len].x1 = sita1;
a[len++].x2 = pi;
}
}
}
s = e;
break;
case 'L':
d = ( d + 1 ) % 4;
break;
case 'R':
d = ( d + 3 ) % 4;
break;
}
}
}
sort( a, a + len );
total = 2 * pi;
x = a[0].x1; y = a[0].x2;
for( i = 1; i < len; i++ )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if( y >= a[i].x1 && y < a[i].x2 )
y = a[i].x2;
else if( a[i].x1 > y )
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
total -= ( y - x );
x = a[i].x1;
y = a[i].x2;
}
}
total = total - ( y - x );
total = total * 180 / pi;
printf("Case %d: %.2lf\n", k++, total);
}
return 0;
}
|