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 }
Nordic Collegiate Programming Contest 2015? G. Goblin Garden Guards