Advertisement
SVXX

LPAIR Tentative Solution

Feb 17th, 2014
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. package easy.chefreunion;
  2. import java.math.int;
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class Main
  7. {
  8.  
  9.     /**
  10.      * @param args
  11.      */
  12.     public static void main(String[] args)
  13.     {
  14.         Scanner s = new Scanner(System.in);
  15.         String input = "";
  16.         ArrayList<Tuple<Integer, Integer>> list = new ArrayList<Tuple<Integer, Integer>>();
  17.         int lines = 0;
  18.         lines = s.nextInt();
  19.         for(int i = 0;  i < lines; i++)
  20.         {
  21.             input = s.nextLine();
  22.             String[] vals = input.split(" ");
  23.             list.add(new Tuple<Integer, Integer>
  24.             (Integer.parseInt(vals[0]), Integer.parseInt(vals[1])));
  25.         }
  26.        
  27.         TestCase ts = new TestCase(lines, list);
  28.         ts.outputAnswer();
  29.     }
  30.  
  31. }
  32.  
  33. class TestCase
  34. {
  35.     int N; //Number of marriage lines. 1 <= N <= 10^5
  36.     ArrayList<Tuple<Integer, Integer>> list = new ArrayList<Tuple<Integer, Integer>>();
  37.     int ans = 0;
  38.    
  39.     TestCase(int noOfLines, ArrayList<Tuple<Integer, Integer>> list)
  40.     {
  41.         N = noOfLines;
  42.         this.list = list;
  43.     }
  44.    
  45.     void findIntersections()
  46.     {
  47.         for(Tuple<Integer, Integer> X : list)
  48.         {
  49.             for(Tuple<Integer, Integer> Y : list)
  50.             {
  51.                 if(X.x > Y.x && X.y < Y.y)
  52.                     ans++;
  53.                 else if(X.x < Y.x && X.y > Y.y)
  54.                     ans++;
  55.             }
  56.         }
  57.     }
  58.    
  59.     void outputAnswer()
  60.     {
  61.         findIntersections();
  62.         System.out.println(ans);
  63.     }
  64.    
  65. }
  66.  
  67. class Tuple<X, Y> {
  68.       public final X x;
  69.       public final Y y;
  70.       public Tuple(X x, Y y) {
  71.         this.x = x;
  72.         this.y = y;
  73.       }
  74.       public boolean equals(Object o)
  75.       {
  76.           if(o instanceof Tuple)
  77.           {
  78.               Tuple<X, Y> s = (Tuple<X, Y>) o;
  79.               if(s.x.equals(this.x) && s.y.equals(this.y))
  80.                   return true;
  81.           }
  82.           return false;
  83.       }
  84.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement