Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class mountain {
- public static void main(String[] args) throws java.io.IOException {
- BufferedReader in = new BufferedReader(new FileReader("mountains.in"));
- PrintWriter out = new PrintWriter(new FileWriter("mountains.out"));
- StringTokenizer tok = new StringTokenizer(in.readLine());
- int numMts = Integer.parseInt(tok.nextToken());
- ArrayList<Mt> mountains = new ArrayList<>();
- int peakX = 0;
- int peakY = 0;
- for (int i = 0; i < numMts; i++) {
- tok = new StringTokenizer(in.readLine());
- peakX = Integer.parseInt(tok.nextToken());
- peakY = Integer.parseInt(tok.nextToken());
- Mt newMount = new Mt(peakX, peakY);
- mountains.add(newMount);
- }
- int count = 0;
- for(Mt m1: mountains) {
- if (m1.visible == true) {
- for (Mt m2: mountains) {
- if (m2.visible == true){
- if (m1.compareTo(m2) == Mt.CONTAINS) {
- m2.visible = false;
- }
- }
- }
- }
- }
- for (int i = 0; i < mountains.size(); i++) {
- if (mountains.get(i).visible == true) {
- count++;
- }
- }
- out.println(count);
- out.close();
- in.close();
- }
- }
- class Mt implements Comparable<Mt> {
- public boolean visible = true;
- public static final int CONTAINS = 1;
- public static final int EQUALS = 0;
- public static final int DISTINCT = -1;
- public int int1;
- public int int2;
- public Mt(int x, int y) {
- this.int1 = y - x;
- this.int2 = x + y;
- }
- public int compareTo(Mt other) {
- if(this.int1 == other.int1 && this.int2 == other.int2) {
- return EQUALS;
- } else if (this.int1 >= other.int1 && this.int2 >= other.int2) {
- return CONTAINS;
- }
- return DISTINCT;
- }
- }
Add Comment
Please, Sign In to add comment