Cod sursa(job #1053153)

Utilizator Pop_EmilPal Tamas Pop_Emil Data 12 decembrie 2013 13:51:57
Problema Trapez Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <algorithm>
#include <iostream>
using namespace std;
#include <stdio.h>
#include <math.h>

FILE *in=fopen("trapez.in","r"),*out=fopen("trapez.out","w");

int N;
long REZ=0;
struct punct
{
    int x,y;
}p[1002];

struct line
 {
    int x1,y1;
    int x2,y2;
    float mer;
 }t[1000020 ];

void _read()
 {
   fscanf(in,"%d",&N);

  for(int i=0;i<N;i++)
    {
     fscanf(in,"%d",&p[i].x);
     fscanf(in,"%d",&p[i].y);
    }

 }

bool cmp(line a,line b)
{
  return a.mer<b.mer;
}

int main()
{
int k=0,i,j;
_read();

 for( i=0;i<N;i++)
  for( j=i+1;j<N;j++)
   {
      // t[k].x1=p[i].x;
      // t[k].y1=p[i].y;
      // t[k].x2=p[j].x;
     //  t[k].y2=p[j].y;
       t[k].mer= (float)(p[i].x-p[j].x)/(p[i].y-p[j].y);
        k++;
  };

 sort(t,t+k,cmp);

  for( i=0;i<k;i++)
  {
   j=i+1;
    while(t[i].mer==t[j].mer)
     j++;

   j=j-i;
   REZ+=j*(j-1)/2;

  }

  fprintf(out,"%ld",REZ);

return 0;
}