Cod sursa(job #2448150)

Utilizator dakataIonescu Valentin-Alexandru dakata Data 15 august 2019 21:23:42
Problema Aria Scor 60
Compilator java Status done
Runda Arhiva educationala Marime 2.53 kb


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.*;
import java.util.*;

/**
 *
 * @author dakata
 */
class Puncte {

    double x;
    double y;

    public Puncte(double x, double y) {
        this.x = x;
        this.y = y;
    }
}

public class Main {

    /**
     * @param args the command line arguments
     */
    /*
    public static void main(String[] args) throws FileNotFoundException {
        // TODO code application logic here
        Scanner scanner = new Scanner(new FileInputStream("adunare.in"));
        PrintStream writer = new PrintStream("adunare.out");
                
        int a = Integer.parseInt(scanner.nextLine());
        int b = Integer.parseInt(scanner.nextLine());
        writer.println(a+b);
        
    }
     */
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader(String f) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) throws FileNotFoundException, IOException {

        FastReader fr = new FastReader("aria.in");
        PrintStream writer = new PrintStream("aria.out");

        double sum = 0;
        int N = Integer.parseInt(fr.nextLine());
        Puncte[] puncte = new Puncte[N + 1];

        for (int i = 0; i < N; i++) {
            puncte[i] = new Puncte(fr.nextDouble(), fr.nextDouble());
        }
        puncte[N] = puncte[0];
        for (int i = 0; i < N; i++) {
            sum += puncte[i].x * puncte[i + 1].y - puncte[i + 1].x * puncte[i].y;
        }
        writer.printf("%.5f\n", sum / 2);
    }

}