Cod sursa(job #3211878)

Utilizator Darius1414Dobre Darius Adrian Darius1414 Data 10 martie 2024 16:41:25
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <algorithm>
#define nmx 1005
using namespace std;
int n,v[nmx],v2[nmx],ct,rsp;
double pant[nmx*nmx];
int main()
{
    ifstream f ("trapez.in");
    ofstream g ("trapez.out");
    f>>n;
    for (int i=1; i<=n; i++)
    {
        f>>v[i]>>v2[i];
        for (int j=1; j<i; j++)
            pant[++ct]=(double)(v2[i]-v2[j])/(v[i]-v[j]);
    }
    sort (pant+1,pant+ct+1);
    int st=1;
    for (int i=1; i<=n; i++)
    {
        if (v[i]!=v[i-1])
        {
            rsp=rsp+(i-st)*(i-st-1)/2;
            st=i;
        }
    }
    if (st!=n)
        rsp=rsp+(n+1-st)*(n-st)/2;
    g<<rsp;
}