Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package CW2010;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class prob11
- {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- int numV = scan.nextInt();
- List<double[]> vert = new ArrayList<>();
- for (int i = 0; i < numV; i++)
- {
- vert.add(new double[] { scan.nextDouble(), scan.nextDouble()});
- }
- int currentV = 0;
- double area = 0;
- while (true)
- {
- if (vert.size() <= 2)
- break;
- double[] v1 = vert.get(currentV % (vert.size() ));
- double[] v2 = vert.get(((currentV+1) % (vert.size() )));
- double[] v3 = vert.get(((currentV+2) % (vert.size() )));
- double a = Math.sqrt(Math.pow(v2[0] - v1[0], 2)
- + Math.pow(v2[1] - v1[1], 2));
- double b = Math.sqrt(Math.pow(v3[0] - v2[0], 2)
- + Math.pow(v3[1] - v2[1], 2));
- double c = Math.sqrt(Math.pow(v1[0] - v3[0], 2)
- + Math.pow(v1[1] - v3[1], 2));
- double p = (a + b + c) / 2;
- area += Math.sqrt(p * (p - a) * (p - b) * (p - c));
- currentV += 1;
- vert.remove(((currentV) % (vert.size())));
- }
- System.out.println(area);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement