Pagini recente » Cod sursa (job #1823960) | Cod sursa (job #2771830) | Cod sursa (job #1802617) | Cod sursa (job #2856058) | Cod sursa (job #2221317)
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = (1LL << 31) - 1;
const double e = 1e-14;
class point
{
private :
int x, y;
public :
point() { x = y = 0; }
point(int a, int b) { x = a, y = b; }
void set(int a, int b) { x = a, y = b; }
double panta(point &other) { if(x == other.x) return inf; return (1.0 * (y - other.y) / (x - other.x)); }
};
vector<point> v;
vector<double> p;
int main()
{
freopen("trapez.in", "r", stdin);
freopen("trapez.out", "w", stdout);
int n, x, y, cnt = 1;
long long ans = 0;
point tmp;
double a, b;
scanf("%d", &n);
for(short i = 0; i < n; i++)
{
scanf("%d%d", &x, &y);
tmp.set(x, y);
v.push_back(tmp);
}
for(int i = 0; i < n - 1; i++)
for(short j = i + 1; j < n; j++)
p.push_back(v[i].panta(v[j]));
sort(p.begin(), p.end());
a = p[0];
for(int i = 1; i < p.size(); i++)
{
b = p[i];
if(fabs(a - b) < e) cnt++;
else ans += cnt * (cnt - 1) / 2, cnt = 1, a = b;
}
ans += cnt * (cnt - 1) / 2;
printf("%lld", ans);
return 0;
}