Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. package CW2010;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class prob11
  8. {
  9.  
  10.     public static void main(String[] args)
  11.     {
  12.         Scanner scan = new Scanner(System.in);
  13.         int numV = scan.nextInt();
  14.         List<double[]> vert = new ArrayList<>();
  15.         for (int i = 0; i < numV; i++)
  16.         {
  17.             vert.add(new double[] { scan.nextDouble(), scan.nextDouble()});
  18.         }
  19.  
  20.         int currentV = 0;
  21.         double area = 0;
  22.         while (true)
  23.         {
  24.             if (vert.size() <= 2)
  25.                 break;
  26.             double[] v1 = vert.get(currentV % (vert.size() ));
  27.             double[] v2 = vert.get(((currentV+1) % (vert.size() )));
  28.             double[] v3 = vert.get(((currentV+2) % (vert.size() )));
  29.             double a = Math.sqrt(Math.pow(v2[0] - v1[0], 2)
  30.                     + Math.pow(v2[1] - v1[1], 2));
  31.             double b = Math.sqrt(Math.pow(v3[0] - v2[0], 2)
  32.                     + Math.pow(v3[1] - v2[1], 2));
  33.             double c = Math.sqrt(Math.pow(v1[0] - v3[0], 2)
  34.                     + Math.pow(v1[1] - v3[1], 2));
  35.             double p = (a + b + c) / 2;
  36.            
  37.             area += Math.sqrt(p * (p - a) * (p - b) * (p - c));
  38.             currentV += 1;
  39.             vert.remove(((currentV) % (vert.size())));
  40.         }
  41.         System.out.println(area);
  42.  
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement