# include <stdio.h>
struct Node
{
int x,y,r;
}A[1011];
int dis(int a,int b,int c,int d ,int e)
{
if(((a-c)*(a-c)+(b-d)*(b-d))<=(e*e)) //个人感觉用R*R表示比求出sqrt()来的快一些
return 1;
else
return 0;
}
int main ()
{
int a,b,c,d,t;
int n,i,j,k;
int count1,count2;
while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
{
count1=0;count2=0;
if(a>c){t=a;a=c;c=t;}
if(b>d){t=b;b=d;d=t;}
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d %d %d",&A[i].x,&A[i].y,&A[i].r);
}
for(i=a;i<=c;i++)
for(j=b;j<=d;j++)
{
if(i>a&&i<c&&j>b&&j<d) continue;
count1++; //求出将军的总个数 因为只有矩形边上才有将军
for(k=1;k<=n;k++)
{
if(dis(i,j,A[k].x,A[k].y,A[k].r))
{
count2++; //求出被温暖的将军的个数
break;
}
}
}
printf("%d\n",count1-count2);
}
return 0;
}
这道题一开始的时候总是超时神马的 想用一个二维数组来储存map的信息 但是很麻烦 最好是用两个for循环 把不符合的变量都去掉
Codeforces #103 div2 B
最新推荐文章于 2013-10-29 22:18:12 发布