Cod sursa(job #2771818)

Utilizator SerbaP123Popescu Serban SerbaP123 Data 29 august 2021 13:33:48
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <bitset>
#define pb(a) push_back(a)
#pragma GCC optimize("Ofast")
using namespace std;

ifstream cin("trapez.in");
ofstream cout("trapez.out");

const int INF = 1e9;

struct point{
    int x, y;
}v[1001];

double pante[1001 * 1001];
int p, n;

int main(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> v[i].x >> v[i].y;
    }
    for(int i = 1; i <= n; ++i){
        for(int j = i + 1; j <= n; ++j){
            if(v[j].x - v[i].x == 0){
                pante[p] = INF;
            }
            else{
                pante[p] = (double) (v[j].y - v[i].y) / (v[j].x - v[i].x);
            }
            p++;
        }
    }
    p--;
    sort(pante + 1, pante + p + 1);
    long long ans = 0, cnt = 1;
    for(int i = 1; i < p; ++i){
        if(pante[i] == pante[i + 1]){
            cnt++;
        }
        else{
            ans += (cnt * (cnt - 1)) / 2;
            cnt = 1;
        }
    }
    cout << ans;
    return 0;
}