Advertisement
Jovfer

acm icpc south neerc taskC

Oct 27th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.73 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.StringTokenizer;
  5.  
  6. public class taskC {
  7.  
  8.     StringTokenizer st;
  9.     BufferedReader in;
  10.     PrintWriter out;
  11.  
  12.     public static void main(String[] args) throws NumberFormatException,
  13.             IOException {
  14.         taskC solver = new taskC();
  15.         solver.open();
  16.         long time = System.currentTimeMillis();
  17.         solver.solve();
  18.         if (!"true".equals(System.getProperty("ONLINE_JUDGE"))) {
  19.             System.out.println("Spent time: "
  20.                     + (System.currentTimeMillis() - time));
  21.             System.out.println("Memory: "
  22.                     + (Runtime.getRuntime().totalMemory() - Runtime
  23.                     .getRuntime().freeMemory()));
  24.         }
  25.         solver.close();
  26.     }
  27.  
  28.     public void open() throws IOException {
  29.         in = new BufferedReader(new InputStreamReader(System.in));
  30.         out = new PrintWriter(new OutputStreamWriter(System.out));
  31.     }
  32.  
  33.     public String nextToken() throws IOException {
  34.         while (st == null || !st.hasMoreTokens()) {
  35.             String line = in.readLine();
  36.             if (line == null)
  37.                 return null;
  38.             st = new StringTokenizer(line);
  39.         }
  40.         return st.nextToken();
  41.     }
  42.  
  43.     public int nextInt() throws NumberFormatException, IOException {
  44.         return Integer.parseInt(nextToken());
  45.     }
  46.  
  47.     public long nextLong() throws NumberFormatException, IOException {
  48.         return Long.parseLong(nextToken());
  49.     }
  50.  
  51.     public double nextDouble() throws NumberFormatException, IOException {
  52.         return Double.parseDouble(nextToken());
  53.     }
  54.  
  55.     class Point {
  56.         public double x, y;
  57.  
  58.         Point(double x, double y) {
  59.             this.x = x;
  60.             this.y = y;
  61.         }
  62.  
  63.         double distTo(Point other) {
  64.             double dx = x - other.x, dy = y - other.y;
  65.             return Math.sqrt(dx * dx + dy * dy);
  66.         }
  67.     }
  68.  
  69.     public void solve() throws NumberFormatException, IOException {
  70.         int n = nextInt();
  71.         HashMap<Long, ArrayList<Integer>> answ = new HashMap<>();
  72.         for (int i = 0; i < n; i++) {
  73.             double allSq = Math.PI * (new Point(nextDouble(), nextDouble()).distTo(new Point(nextDouble(), nextDouble())))
  74.                     * (new Point(nextDouble(), nextDouble()).distTo(new Point(nextDouble(), nextDouble()))) / 4;
  75.             int r = nextInt();
  76.             double s = 0;
  77.             for (int j = 0; j < r; j++) {
  78.                 s += getS(new Point(nextDouble(), nextDouble()), new Point(nextDouble(), nextDouble()), new Point(nextDouble(), nextDouble()), new Point(nextDouble(), nextDouble()));
  79.             }
  80.             double rank = allSq / s;
  81.             long rankL = (long) (rank * 10000);
  82.             if (!answ.containsKey(rankL)) answ.put(rankL, new ArrayList<Integer>());
  83.             answ.get(rankL).add(i);
  84.         }
  85.         int[] ind = new int[n];
  86.         int pos = 1;
  87.         for (Long cur : answ.keySet()) {
  88.             for (Integer integer : answ.get(cur)) {
  89.                 ind[integer] = pos;
  90.             }
  91.             pos++;
  92.         }
  93.         for (int i : ind) {
  94.             out.print(i + " ");
  95.         }
  96.     }
  97.  
  98.     private double getS(Point point1, Point point2, Point point3, Point point4) {
  99.         return getS(point1, point2, point4) + getS(point2, point3, point4);
  100.     }
  101.  
  102.     private double getS(Point point1, Point point2, Point point3) {
  103.         double a = point1.distTo(point2), b = point2.distTo(point3), c = point3.distTo(point1);
  104.         double p = (a + b + c) / 2;
  105.         return Math.sqrt(p * (p - a) * (p - b) * (p - c));
  106.     }
  107.  
  108.     public void close() {
  109.         out.flush();
  110.         out.close();
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement