如果用set来做的话,这个题就变的非常非常水了, 完全不用考虑精度问题。
用一个结构体存储直线,然后插到集合里,最后输出集合的大小即可。
然后求公约数的时候有个负数问题,后来发现我多虑了。
|
/* ID: sdj22251 PROG: calfflac LANG: C++ */ #include <iostream> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <cmath> #include <ctime> #define MAX 100000000 #define LOCA #define PI acos(-1.0) using namespace std; struct line { int x, y; bool operator < (const line & a) const // 重载操作符,其实就是写个排序。 如果不重载,结构体是没法往set里面塞的。 { if(a.x == x) return y < a.y; return x < a.x; } }; int main() { #ifdef LOCAL freopen("ride.in","r",stdin); freopen("ride.out","w",stdout); #endif int n, i, j, x[202], y[202]; set<line>st; scanf("%d", &n); for(i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]); for(i = 0; i < n - 1; i++) { for(j = i + 1; j < n; j++) { line p; p.x = x[i] - x[j]; p.y = y[i] - y[j]; int cd = __gcd(p.x, p.y); //系统自带的求公约数函数。 p.x /= cd; p.y /= cd; st.insert(p); } } printf("%d\n", st.size()); return 0; }