Nordic Collegiate Programming Contest 2015 G. Goblin Garden Guards
In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city of Mlohkcots. Goblins—small, green critters—love nothing more than to introduce additional entropy into the calm and ordered lives of ordinary people. They fear little, but one of the few things they fear is water.
The goblin invasion has now reached the royal gardens, where the goblins are busy stealing fruit, going for joyrides on the lawnmower and carving the trees into obscene shapes, and King Lrac Fatsug has decreed that this nonsense stop immediately!
Thankfully, the garden is equipped with an automated sprinkler system. Enabling the sprinklers will soak all goblins within range, forcing them to run home and dry themselves.
Serving in the royal garden guards, you have been asked to calculate how many goblins will remain in the royal garden after the sprinklers have been turned on, so that the royal gardeners can plan their next move.
Input Format
The input starts with one integer 1≤g≤100000, the number of goblins in the royal gardens.
Then, for each goblin follows the position of the goblin as two integers, 1≤xi≤10000 and1≤yi≤10000. The garden is flat,
square and all distances are in meters. Due to quantum interference, several goblins can occupy exactly the same spot
n the garden.Then follows one integer 1≤m≤20000, the number of sprinklers in the garden.Finally, for each sprinkler follows the location of the sprinkler as two integers 1≤xi≤10000 and 1≤yi≤10000, and the integer radius 1≤r≤100 of the area it covers,meaning that any goblin at a distance of at most rr from the point (xi,yi) will be soaked by this sprinkler.
There can be several sprinklers in the same location.
Output Format
Output the number of goblins remaining in the garden after the sprinklers have been turned on.
样例输入
5 0 0 100 0 0 100 100 100 50 50 1 0 0 50
样例输出
4
题目来源
Nordic Collegiate Programming Contest 2015
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <vector> 5 #include <string> 6 #include <string> 7 #include <map> 8 #include <cmath> 9 #include <set> 10 #include <algorithm> 11 using namespace std; 12 typedef long long ll; 13 int g,m; 14 const int N=1e5+9; 15 const int M=1e4+9; 16 struct Node{ 17 int x, y; 18 }nod[N]; 19 bool vis[M][M];//bool变量占用一个字节的内存1k==1024字节 20 //int vis[M][M] int : 4字节 21 int main() 22 { 23 scanf("%d",&g); 24 for(int i=0;i<g;i++){ 25 scanf("%d%d",&nod[i].x,&nod[i].y); 26 } 27 scanf("%d",&m); 28 int x,y,r; 29 memset(vis,0,sizeof(vis)); 30 //20000*10^8==2*10^12 31 for(int i=0;i<m;i++){ 32 scanf("%d%d%d",&x,&y,&r); 33 for(int kx=max(0,x-r);kx<=min(x+r,10000);kx++){ 34 for(int ky=max(0,y-r);ky<=min(y+r,10000);ky++){ 35 if(((x-kx)*(x-kx))+((y-ky)*(y-ky))<=r*r){ 36 vis[kx][ky]=1; 37 } 38 } 39 } 40 } 41 int ans=0; 42 for(int i=0;i<g;i++){ 43 if(!vis[nod[i].x][nod[i].y]) 44 ans++; 45 } 46 printf("%d\n",ans); 47 return 0; 48 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现