川大邀请赛 A
计算几何
#include <bits/stdc++.h>
#define INF (int)(1e9)
#define maxn 1000010
#define sigma_size 100
using namespace std;
#define ll int
#define N 100050
struct Point {
int x, y;
Point(double x = 0, double y = 0): x(x), y(y) { }
};
typedef Point Vector;
Point operator + (Point A, Point B) { return Point(A.x+B.x, A.y+B.y); }
Point operator - (Point A, Point B) { return Point(A.x-B.x, A.y-B.y); }
Point operator * (Point A, double p) { return Point(A.x*p, A.y*p); }
Point operator / (Point A, double p) { return Point(A.x/p, A.y/p); }
bool operator < (const Point& a, const Point& b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
double Cross(Point A, Point B) { return A.x*B.y - A.y*B.x; }
struct Segment {
Vector v;
Point p1, p2;//两端点
};
bool operator < (const Segment& a, const Segment& b) {
return a.v < b.v;
}
bool SegmentCollinear(Segment a, Segment b) {
Vector _1, _2;
_1 = a.p2 - a.p1;
_2 = b.p1 - a.p1;
if (Cross(_1, _2) == 0) return true;
return false;
}
Point p[550];
Segment seg[360000];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
if (n == 0) break;
for (int i = 0; i < n; ++ i) {
scanf("%d%d", &p[i].x, &p[i].y);
}
sort(p, p+n);
int l = 0;
for (int i = 0; i < n; ++ i) {
for (int j = i+1; j < n; ++ j) {
seg[l].p1 = p[i]; seg[l].p2 = p[j];
seg[l].v = seg[l].p2 - seg[l].p1;
++ l;
}
}
sort(seg, seg+l);
int res = 0;
for (int i=0, j=0; i < l; i=j) {
while(seg[i].v.x == seg[j].v.x && seg[i].v.y == seg[j].v.y) j++;
for (int ii = i; ii < j; ++ ii) {
for (int jj = ii+1; jj < j; ++ jj) {
if (!SegmentCollinear(seg[ii], seg[jj])) {
// cout << ii << " " << jj << endl;
res ++;
}
}
}
}
res /= 2;
printf("%d\n", res);
}
}