Pagini recente » Cod sursa (job #1283864) | Cod sursa (job #1751514) | Istoria paginii utilizator/spiromanii_messi | Cod sursa (job #283076) | Cod sursa (job #865587)
Cod sursa(job #865587)
#include <fstream>
#include <algorithm>
using namespace std;
//mai mult
#define inf 2000000005
struct element
{
int x;
int y;
}pante[100005];
element panta(int x1,int y1, int x2, int y2)
{
y2-=x1;
x2-=x1;
element a;
a.y=y2;
a.x=x2;
if(x2==0)
{
a.y=inf;
a.x=1;
}
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("trapez.in");
ofstream fout("trapez.out");
int n,i,j;
int vx[100005];
int vy[100005];
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]);
}
//fout<<"da\n";
int trapeze=0;
sort(pante,pante+poz);
int bune=0;
//fout<<pante[0].x<<' '<<pante[0].y<<'\n';
for(i=1;i<poz;i++)
{
//fout<<pante[i].x<<' '<<pante[i].y<<'\n';
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;
}