Advertisement
Nickpips

Rat Attack

Mar 13th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import java.io.FileNotFoundException;
  2. import java.io.PrintWriter;
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class ratattack {
  7. public void run() {
  8. int T = in.nextInt();
  9. for (int t = 1; t <= T; t++) {
  10. int d = in.nextInt();
  11. int n = in.nextInt();
  12.  
  13. int[][] grid = new int[1025][1025];
  14.  
  15. for (int i = 0; i < n; i++) {
  16. int X = in.nextInt();
  17. int Y = in.nextInt();
  18. int pop = in.nextInt();
  19. for (int x = X - d; x <= X + d; x++) {
  20. for (int y = Y - d; y <= Y + d; y++) {
  21. try {
  22. grid[x][y] += pop;
  23. } catch (Exception e) {
  24.  
  25. }
  26. }
  27. }
  28. }
  29. int m = grid[0][0];
  30. int X = 0;
  31. int Y = 0;
  32. for (int x = 0; x < 1025; x++) {
  33. for (int y = 0; y < 1025; y++) {
  34. if (grid[x][y] > m) {
  35. m = grid[x][y];
  36. X = x;
  37. Y = y;
  38. }
  39. }
  40. }
  41. System.out.println(X + " " + Y + " " + m);
  42. }
  43. }
  44.  
  45. public void debug(Object n) {
  46. System.out.println("\t\tDEBUG\t\t" + n.toString().replace("\n", "\n\t\tDEBUG\t\t"));
  47. }
  48.  
  49. static Scanner in = new Scanner(System.in);
  50. static PrintWriter out = new PrintWriter(System.out);
  51.  
  52. public static void main(String[] args) throws FileNotFoundException {
  53. // in = new Scanner(new File("ratattack.in"));
  54. // out = new PrintWriter(new File("ratattack.out"));
  55.  
  56. (new ratattack()).run();
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement