Sicily 1795 Table tennis

几何题. 仔细一点即可通过. 需要注意的是, 为了提高效率, 需要对每次hit的坐标进行预处理. 即判断该点是否在某个圆的范围(包住圆方形)内, 如果不在不计算, 如果在的话判断出这个hit的坐标与所在圆的圆心的距离. 若距离小于该圆半径, 那么在圆内, 算是击中.

代码
/* platero 2010-11-5 */
#include
<stdio.h>
#include
<math.h>
#define MAXHITS 60

typedef
struct Point
{
int x;
int y;
};

int main()
{
int t, n, i, hit_point;
struct Point curhit;
scanf(
"%d", &t);
while(t--)
{
hit_point
= 0;
scanf(
"%d", &n);
/* 输入hits座标 */
for(i = 0; i < n; i++)
{
scanf(
"%d%d", &curhit.x, &curhit.y);
/* 是否在大圆范围内 */
if(curhit.x > 10 && curhit.x < 50)
{
if(curhit.y > 10 && curhit.y < 50)
{
if(pow((curhit.x - 30),2) + pow((curhit.y-30), 2) < 400)
{
hit_point
+= 1;
}
}
}
else if(curhit.x > 90 && curhit.x < 110)
{
if(curhit.y > 20 && curhit.y < 40)
{
if(pow((curhit.x - 100),2) + pow((curhit.y-30), 2) < 100)
{
hit_point
+= 2;
}
}
}
else if(curhit.x > 165 && curhit.x < 175)
{
if(curhit.y > 25 && curhit.y < 35)
{
if(pow((curhit.x - 170),2) + pow((curhit.y-30), 2) < 25)
{
hit_point
+= 3;
}
}
}
}
printf(
"%d\n", hit_point);
}
return 0;
}

 

posted @ 2010-11-05 17:09  普兒  阅读(471)  评论(0编辑  收藏  举报