muffinman1015

Jan2019SilverIII

Jan 20th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class mountain {
  5.  
  6. public static void main(String[] args) throws java.io.IOException {
  7. BufferedReader in = new BufferedReader(new FileReader("mountains.in"));
  8. PrintWriter out = new PrintWriter(new FileWriter("mountains.out"));
  9. StringTokenizer tok = new StringTokenizer(in.readLine());
  10.  
  11. int numMts = Integer.parseInt(tok.nextToken());
  12. ArrayList<Mt> mountains = new ArrayList<>();
  13. int peakX = 0;
  14. int peakY = 0;
  15. for (int i = 0; i < numMts; i++) {
  16. tok = new StringTokenizer(in.readLine());
  17. peakX = Integer.parseInt(tok.nextToken());
  18. peakY = Integer.parseInt(tok.nextToken());
  19. Mt newMount = new Mt(peakX, peakY);
  20. mountains.add(newMount);
  21. }
  22.  
  23. int count = 0;
  24. for(Mt m1: mountains) {
  25. if (m1.visible == true) {
  26. for (Mt m2: mountains) {
  27. if (m2.visible == true){
  28. if (m1.compareTo(m2) == Mt.CONTAINS) {
  29. m2.visible = false;
  30. }
  31. }
  32. }
  33. }
  34. }
  35.  
  36. for (int i = 0; i < mountains.size(); i++) {
  37. if (mountains.get(i).visible == true) {
  38. count++;
  39. }
  40. }
  41.  
  42. out.println(count);
  43. out.close();
  44. in.close();
  45.  
  46. }
  47. }
  48.  
  49. class Mt implements Comparable<Mt> {
  50. public boolean visible = true;
  51. public static final int CONTAINS = 1;
  52. public static final int EQUALS = 0;
  53. public static final int DISTINCT = -1;
  54. public int int1;
  55. public int int2;
  56.  
  57. public Mt(int x, int y) {
  58. this.int1 = y - x;
  59. this.int2 = x + y;
  60. }
  61.  
  62. public int compareTo(Mt other) {
  63. if(this.int1 == other.int1 && this.int2 == other.int2) {
  64. return EQUALS;
  65. } else if (this.int1 >= other.int1 && this.int2 >= other.int2) {
  66. return CONTAINS;
  67. }
  68. return DISTINCT;
  69. }
  70. }
Add Comment
Please, Sign In to add comment