NOJ [1040] Meeting

这是一道CF的题,不知道别人怎么做的

  • 问题描述
  • The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose sides are parallel to the coordinate axes and whose vertexes are located at the integer points of the plane. At each integer point which belongs to the table perimeter there is a chair in which a general sits.

    Some points on the plane contain radiators for the generals not to freeze in winter. Each radiator is characterized by the numberri — the radius of the area this radiator can heat. That is, if the distance between some general and the given radiator is less than or equal to ri, than the general feels comfortable and warm. Here distance is defined as Euclidean distance, so the distance between points (x1, y1) and (x2, y2) is 

    Each general who is located outside the radiators' heating area can get sick. Thus, you should bring him a warm blanket. Your task is to count the number of warm blankets you should bring to the Super Duper Secret Place.

    The generals who are already comfortable do not need a blanket. Also the generals never overheat, ever if they are located in the heating area of several radiators. The radiators can be located at any integer points on the plane, even inside the rectangle (under the table) or on the perimeter (directly under some general). Even in this case their radius does not change.

  • 输入
  • The first input line contains coordinates of two opposite table corners xa, ya, xb, yb (xa ≠ xb, ya ≠ yb). The second line contains integer n — the number of radiators (1 ≤ n ≤ 10^3). Then n lines contain the heaters' coordinates as "xi yi ri", the numbers are separated by spaces. All input data numbers are integers. The absolute value of all coordinates does not exceed 1000, 1 ≤ ri ≤ 1000. Several radiators can be located at the same point.
  • 输出
  • Print the only number — the number of blankets you should bring.
  • 样例输入
  • 2 5 4 2
    3
    3 1 2
    5 3 1
    1 3 2
    5 2 6 3
    2
    6 2 2
    6 5 3
  • 样例输出
  • 4
    0
我们把题目抽象出来就是,给你一个矩形,上面的点都是整数点,然后給一些圆,问你不能被这些圆包含的点的个数

我的做法是,先把点存起来,然后在每次输入圆的时候,去看它可以包含哪些点,但要注意不要重复包含

下面是我AC的代码

#include<stdio.h>
#include<math.h>
struct node
{
  int x,y;
  bool vis;
  node()
  {vis=false;}
};

int max(int a,int b)
{
  return a>b?a:b;
}

int min(int a,int b)
{
  return a<b?a:b;
}
bool dist(const int x1,const int y1,const int x2,const int y2,const int r)
{
  int len=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
  if(len<=r*r)  return true;
  return false;
}
int main()
{
  int a,b,c,d,xa,ya,xb,yb,n;
  while(~scanf("%d%d%d%d",&a,&b,&c,&d))
  {
    int i,j,k=0;
    node point[1010];
    xa=min(a,c);
    xb=max(a,c);
    ya=min(b,d);
    yb=max(b,d);
    for(i=ya;i<=yb;i++)
    {
      point[k].x=xa;
      point[k].y=i;
      k++;
    }
   
    for(i=xa+1;i<xb;i++)
    {
      point[k].x=i;
      point[k].y=ya;
      k++;
      point[k].x=i;
      point[k].y=yb;
      k++;
    } 
    for(i=ya;i<=yb;i++)
    {
      point[k].x=xb;
      point[k].y=i;
      k++;
    }
    scanf("%d",&n);
    int xi,yi,ri,cnt=0;
    for(j=1;j<=n;j++)
    {
      scanf("%d%d%d",&xi,&yi,&ri);
      for(i=0;i<k;i++)
      {
        if(dist(xi,yi,point[i].x,point[i].y,ri) && !point[i].vis)//这个圆可以包含这个点,而且这个点没被包含
        {
          point[i].vis=true;//标记点已经在里边
          cnt++;
        }
      }
    }
    printf("%d\n", k-cnt);
  }
  return 0;
}


你可能感兴趣的:(NOJ [1040] Meeting)