Cod sursa(job #1081194)

Utilizator Aleks10FMI - Petrache Alex Aleks10 Data 13 ianuarie 2014 12:38:51
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.08 kb
/*#include <fstream>
#include <vector>
#include <algorithm>
#include <iostream>

#define x first
#define y second

using namespace std;

ifstream f("trapez.in");
ofstream g("trapez.out");

const int MAX_N = 1005;

int n, ans;
vector < pair <int, int> > Point;
vector <double> Slopes;

void read() {
    f >> n;
    for (int i = 1; i <= n; i++) {
        int x, y;
        f >> x >> y;
        Point.push_back (make_pair (x, y));
    }
}

void solve() {
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++) {
            double slope = (double)(Point[j].y - Point[i].y) / (Point[j].x - Point[i].x);
            Slopes.push_back (slope);
        }

    sort (Slopes.begin(), Slopes.end());
    for(int i=0;i<Slopes.size();i++)
        cout<<Slopes[i]<<endl;
    int i = 0;
    while (i < Slopes.size()) {
        int j = i;
        while (j < Slopes.size() && Slopes[i] == Slopes[j])
            j++;
        int frecv = j - i;
        ans += frecv * (frecv - 1) / 2;
        i = j;
    }
}

int main() {
    read();
    solve();

    g << ans;

    return 0;
}

*/#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

vector <pair<int,int> > puncte;
vector <double> pante;
int main()
{
    int n,i,x,y,j;
    ifstream f("trapez.in");
    ofstream g("trapez.out");
    f>>n;
    for(i=1;i<=n;i++){
        f>>x>>y;
        puncte.push_back(make_pair(x,y));
    }

    double panta=0;
    for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++){
                panta=(double)(puncte[j].second-puncte[i].second)/(puncte[j].first-puncte[i].first);
            pante.push_back(panta);
        }
    sort(pante.begin(),pante.end());

    int nr=0,dif;
    for(i=0;i<pante.size();i++){
        j=i;
       // cout<<j<<" ";
        while(pante[i]==pante[j] && j<pante.size())
            j++;
      //  cout<<j<<endl;
        dif=j-i;
        i=j-1;
        nr+=dif*(dif-1)/2;
    }
    //for(i=0;i<pante.size();i++)
     //   cout<<pante[i]<<endl;
    g<<nr;
    return 0;
}