正文
Gym - 100781G-Goblin Garden Guards
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
题目链接:https://nanti.jisuanke.com/t/28882
解题思路:单纯的判断点是否在圆内,一一遍历圆外切正方形内的点即可,注意,该题要建个结构体数组存每个地精的位置,再bool个map数组用来标记点是否在圆内,map数组不能用int否则会超内存。
#include<iostream>
using namespace std;
int n,m,ans;
bool map[][];
int in(int x,int y)
{
if(x<||x>||y<||y>)
return ;
else return ;
}
struct node{
int x,y;
}a[];
int main()
{
cin>>n;
for(int i=;i<n;i++)
{
cin>>a[i].x>>a[i].y;
map[a[i].x][a[i].y]=;
}
cin>>m;
for(int i=;i<m;i++)
{
int x,y,r;
cin>>x>>y>>r;
for(int j=x-r;j<=x+r;j++)
{
for(int k=y-r;k<=y+r;k++)
{
if(in(j,k))
{
if((j-x)*(j-x)+(k-y)*(k-y)<=r*r)
map[j][k]=;
}
}
}
}
ans=;
for(int i=;i<n;i++)
if(map[a[i].x][a[i].y])
ans++;
cout<<ans<<endl;
return ;
}