本站遷移

因為我最近租用了網路空間以及網域,
故本站已遷移至新網站~
這邊的資訊已經正在進行搬移的工作~
希望各位可以到新網站去逛XD

New Website:
http://knightzone.org/

搜尋此網誌

2011年3月11日 星期五

[UVa]10589:Area

計算點距離四邊點的距離是否都在a以內即可得解。

[C](0.112)
#include<stdio.h>
double distance( double x1, double y1, double x2, double y2 )
{
return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}
int main()
{
int N, a;
while( scanf( "%d%d", &N, &a ) != EOF && N != 0 && a != 0 )
{
int i;
int M = 0;
for( i = 0 ; i < N ; i++ )
{
double x, y;
scanf( "%lf%lf", &x, &y );
if( distance( x, y, 0.0, 0.0 ) <= (double)(a*a) )
if( distance( x, y, 0.0, (double)a ) <= (double)(a*a) )
if( distance( x, y, (double)a, (double)a ) <= (double)(a*a) )
if( distance( x, y, (double)a, 0.0 ) <= (double)(a*a) )
M++;
}
printf( "%.5lf\n", (double)M/(double)N*(double)a*(double)a );
}
return 0;
}
view raw UVa10589.c hosted with ❤ by GitHub

0 意見:

張貼留言