其他分享
首页 > 其他分享> > 题解:Transmitters(几何,叉积)

题解:Transmitters(几何,叉积)

作者:互联网

In a wireless network with multiple transmitters sending on the same frequencies, it is often a requirement that signals don’t overlap, or at least that they don’t conflict. One way of accomplishing this is to restrict a transmitter’s coverage area. This problem uses a shielded transmitter that only broadcasts in a semicircle.
transmitter T is located somewhere on a 1,000 square meter grid. It broadcasts in a semicircular area of radius r. The transmitter may be rotated any amount, but not moved. Given N points anywhere on the grid, compute the maximum number of points that can be simultaneously reached by the transmitter’s signal. Figure 1 shows the same data points with two different transmitter rotations.
input coordinates are integers (0-1000). The radius is a positive real number greater than 0. Points on the boundary of a semicircle are considered within that semicircle. There are 1-150 unique points to examine per transmitter. No points are at the same location as the transmitter.
put
nput consists of information for one or more independent transmitter problems. Each problem begins with one line containing the (x,y) coordinates of the transmitter followed by the broadcast radius, r. The next line contains the number of points N on the grid, followed by N sets of (x,y) coordinates, one set per line. The end of the input is signalled by a line with a negative radius; the (x,y) values will be present but indeterminate. Figures 1 and 2 represent the data in the first two example data sets below, though they are on different scales. Figures 1a and 2 show transmitter rotations that result in maximal coverage.
Output
For each transmitter, the output contains a single line with the maximum number of points that can be contained in some semicircle.

    Sample Input
    25 25 3.5
    7
    25 28
    23 27
    27 27
    24 23
    26 23
    24 29
    26 29
    350 200 2.0
    5
    350 202
    350 199
    350 198
    348 200
    352 200
    995 995 10.0
    4
    1000 1000
    999 998
    990 992
    1000 999
    100 100 -2.5

    Sample Output
    3
    4
    4

给圆心,半径,求半圆内最多有几个点
同一侧 叉积>=0

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
struct node{
 int x,y;
}point[200];
const double epsi=1e-10;
double distance(int x1,int y1,int x2,int y2)
{
 return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
bool chaji(int x1,int y1,int x2,int y2)
{ 
 if((x1*y2-x2*y1)>=0)
  return true;
 else  
  return false;
}
int main()
{
 int x,y,n,tip,sum;
 double r;
 while(~scanf("%d%d%lf",&x,&y,&r)&&r>=0)
 {
  tip=0;
  point[0].x=x;point[0].y=y;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
   scanf("%d%d",&x,&y);
   if(r>=distance(x,y,point[0].x,point[0].y)) //排除不在半径内的 
   {
     point[++tip].x=x;point[tip].y=y;
   }
  }
  int maxn=0;
  for(int i=1;i<=tip;i++)
  {
   sum=0;                 //选一点连成半圆边 
   for(int j=1;j<=tip;j++) //判断是否在同一方向 
   {
    if(chaji(point[i].x-point[0].x,
            point[i].y-point[0].y,
            point[j].x-point[0].x,
            point[j].y-point[0].y
     ))
     sum++;
   }
   maxn=max(maxn,sum); 
  }
  printf("%d\n",maxn);
 }
    return 0;
}

标签:transmitter,include,Transmitters,point,int,题解,points,叉积,y2
来源: https://blog.csdn.net/weixin_43540515/article/details/98954224