Pagini recente » Cod sursa (job #1192713) | Cod sursa (job #3189660) | Cod sursa (job #2103061) | Cod sursa (job #2685506) | Cod sursa (job #1137894)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int cmmdc(int a,int b)
{
if (b==0)
return a;
return cmmdc(b,a%b);
}
void redo(pair <int,int> &fr)
{
//cout<<"RE"<<fr.first<<' '<<fr.second<<"DO";
if (fr.first==0)
{
fr.second=1;
return;
}
int d=cmmdc(fr.first,fr.second);
fr.first=fr.first/d;
fr.second=fr.second/d;
}
pair <int,int> fr;
int a,b,n,i,x,y,i1,k;
vector <pair <int,int> > v,vl;
bool fless(pair <int,int> const f1, pair <int,int> const f2)
{
return (f1.first*f2.second)<(f2.first*f1.second);
}
int main(void)
{
FILE * f;
f=fopen("trapez.in","r");
ofstream g("trapez.out");
fscanf(f,"%d",&n);
for (i=1;i<=n;i++)
{
fscanf(f,"%d%d",&x,&y);
v.push_back(make_pair(x,y));
}
for (i=0;i<v.size();i++)
for (i1=i+1;i1<v.size();i1++)
{
y=v[i1].second-v[i].second;
x=v[i1].first-v[i].first;
if (v[i1].first<v[i].first)
{
x=-x;
y=-y;
}
if ((v[i1].first==v[i].first)&&(v[i1].second<v[i].second))
{
x=-x;
y=-y;
}
fr.first=y;
fr.second=x;
//cout<<fr.first<<' '<<fr.second<<" ";
redo(fr);
//cout<<fr.first<<' '<<fr.second<<"\n\n";
vl.push_back(fr);
}
sort(vl.begin(),vl.end(),&fless);
//cout<<vl[0].first<<' '<<vl[0].second<<'\n';
for (i=1;i<vl.size();i++)
{
if ((vl[i].first==vl[i-1].first)&&(vl[i].second==vl[i-1].second))
k++;
//cout<<vl[i].first<<' '<<vl[i].second<<'\n';
}
g<<k;
return 0;
}