Pagini recente » Cod sursa (job #56621) | Cod sursa (job #696317) | Cod sursa (job #973757) | Cod sursa (job #1751737) | Cod sursa (job #865554)
Cod sursa(job #865554)
#include <fstream>
#include <algorithm>
using namespace std;
//mai mult
#define inf 2000000005
struct element
{
int x;
int y;
}pante[1005];
element panta(int x1,int y1, int x2, int y2)
{
x1-=x2;
y1-=x2;
element a;
a.x=x1;
a.y=y1;
if(x1==0)
{
a.x=1;
a.y=inf;
}
return a;
}
bool operator<(const element &a,const element &b)
{
return ((a.x*b.y)<(b.x*a.y));
}
bool compara(const element &a,const element &b)
{
return ((a.x*b.y)==(b.x*a.y));
}
int main()
{
ifstream fin("trapeze.in");
ofstream fout("trapeze.out");
int n,i,j;
int vx[1005];
int vy[1005];
int poz=0;
fin>>n;
for(i=0;i<n;i++)
{
fin>>vx[i];
fin>>vy[i];
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(vx[i]!=vx[j] || vy[i]!=vy[j])
{
pante[poz++]=panta(vx[i],vy[i],vx[j],vy[j]);
}
int trapeze=0;
sort(pante,pante+poz);
int bune=0;
for(i=1;i<poz;i++)
{
if(compara(pante[i],pante[i-1])==1)
bune++;
else
{
trapeze+=(((bune)*(bune+1))/2);
bune=0;
}
}
fout<<trapeze<<'\n';
fin.close();
fout.close();
return 0;
}