Pagini recente » Cod sursa (job #1279064) | Cod sursa (job #2362990) | Cod sursa (job #1683158) | Cod sursa (job #762942) | Cod sursa (job #2519345)
#include <bits/stdc++.h>
#define x first
#define y second
#define inf 1.0/0.0
std::ifstream fin("trapez.in");
std::ofstream fout("trapez.out");
typedef long long ll;
ll n, sol;
std::pair<ll, ll> list[1005];
std::unordered_map<double, std::unordered_map<double, ll> > m_l;
std::unordered_map<double, std::unordered_map<double, ll> >::iterator itm_l;
std::unordered_map<double, ll> m;
std::unordered_map<double, ll>::iterator itm;
double calc_m(std::pair<ll, ll> p1, std::pair<ll, ll> p2);
double calc_l(std::pair<ll, ll> p1, std::pair<ll, ll> p2);
int main()
{
fin>>n;
for(int i=1; i<=n; ++i){
fin>>list[i].x>>list[i].y;
}
for(int i=1; i<n; ++i){
for(int j=i+1; j<=n; ++j){
++m[calc_m(list[i], list[j])];
++m_l[calc_m(list[i], list[j])][calc_l(list[i], list[j])];
}
}
itm_l=m_l.begin();
while(itm_l!=m_l.end()){
ll sum=m[itm_l->first];
///std::cout<<itm_l->first<<"\n";
itm=(itm_l->second).begin();
while(itm!=(itm_l->second).end()){
sum-=itm->second;
///std::cout<<itm->second<<" ";
sol=sol+(itm->second)*((itm->second)-1)+(itm->second)*sum;
++itm;
}
///std::cout<<"\n";
++itm_l;
}
fout<<sol;
return 0;
}
double calc_m(std::pair<ll, ll> p1, std::pair<ll, ll> p2){
return 1.0*(p2.y-p1.y)/(p2.x-p1.x);
}
double calc_l(std::pair<ll, ll> p1, std::pair<ll, ll> p2){
return 1.0*sqrt((p2.y-p1.y)*(p2.y-p1.y)+(p2.x-p1.x)*(p2.x-p1.x));
}