Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package easy.chefreunion;
- import java.math.int;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Main
- {
- /**
- * @param args
- */
- public static void main(String[] args)
- {
- Scanner s = new Scanner(System.in);
- String input = "";
- ArrayList<Tuple<Integer, Integer>> list = new ArrayList<Tuple<Integer, Integer>>();
- int lines = 0;
- lines = s.nextInt();
- for(int i = 0; i < lines; i++)
- {
- input = s.nextLine();
- String[] vals = input.split(" ");
- list.add(new Tuple<Integer, Integer>
- (Integer.parseInt(vals[0]), Integer.parseInt(vals[1])));
- }
- TestCase ts = new TestCase(lines, list);
- ts.outputAnswer();
- }
- }
- class TestCase
- {
- int N; //Number of marriage lines. 1 <= N <= 10^5
- ArrayList<Tuple<Integer, Integer>> list = new ArrayList<Tuple<Integer, Integer>>();
- int ans = 0;
- TestCase(int noOfLines, ArrayList<Tuple<Integer, Integer>> list)
- {
- N = noOfLines;
- this.list = list;
- }
- void findIntersections()
- {
- for(Tuple<Integer, Integer> X : list)
- {
- for(Tuple<Integer, Integer> Y : list)
- {
- if(X.x > Y.x && X.y < Y.y)
- ans++;
- else if(X.x < Y.x && X.y > Y.y)
- ans++;
- }
- }
- }
- void outputAnswer()
- {
- findIntersections();
- System.out.println(ans);
- }
- }
- class Tuple<X, Y> {
- public final X x;
- public final Y y;
- public Tuple(X x, Y y) {
- this.x = x;
- this.y = y;
- }
- public boolean equals(Object o)
- {
- if(o instanceof Tuple)
- {
- Tuple<X, Y> s = (Tuple<X, Y>) o;
- if(s.x.equals(this.x) && s.y.equals(this.y))
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement