test

#include #include #include #include #include using namespace std; int minNumberOfLines(int num, int timX, int timY, int** coordinates) { #define MAX LDBL_MAX #define EXP 1e-9 struct _line { double k; double b; _line() :k(MAX), b(0) { } bool operator<(const _line & rhs) const { if (k < rhs.k) { return true; } if (abs(k - rhs.k) < EXP) { return b < rhs.b; } return false; } bool operator==(const _line & rhs)const { return abs(k - rhs.k) < EXP && abs(b - rhs.b) < EXP; } }; set<_line>rst; while (!rst.empty()) { rst.clear(); } int i = 0; int x, y; while (num--) { _line tmp; (int*)((int *)(coordinates)+2*i) x = coordinates[i][0]; y = coordinates[i][1]; if (x == timX) { tmp.k = MAX; tmp.b = 0; } else { tmp.k = (y - timY)*1.0 / (x - timX); tmp.b = timY - timX*tmp.k; } rst.insert(tmp); i++; } return rst.size(); } int main() { int num, timX, timY; scanf("%d%d%d", &num, &timX, &timY); int **coordinates = (int **)malloc(sizeof(int *)* num); int i = 0; while (i
posted @ 2017-09-18 21:51  蒋明昊  阅读(83)  评论(0)    收藏  举报