RQNOJ 150轰炸(求最多有几个点共线)

/*
*  题意:求最多有多少个点共线 
*  思路:枚举两点求直线,枚举有多少个点在直线上 
*/

#include <cstdio>
#include <iostream>

using namespace std;

const int N = 705;

struct point {
	int x;
	int y;
}p[N];

int solve(int n) {
	int a, b, c, counts, ans = -1;
	for (int i=0; i<n; ++i) { 
		for (int j=i+1; j<n; ++j) {
			a = p[j].y - p[i].y;  //一般直线方程系数 
			b = p[i].x - p[j].x;
			c = p[i].y * p[j].x - p[i].x * p[j].y;
			counts = 0;
			for (int k=0; k<n; ++k) {//枚举判断有几个点在直线上 
				if (a*p[k].x+b*p[k].y+c == 0) ++counts;
			}
			if (counts > ans) ans = counts;
		}
	}
	return ans;
}

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		for (int i=0; i<n; ++i) scanf("%d%d", &p[i].x, &p[i].y);
		int ans = solve(n);
		printf ("%d\n", ans);
	}
	return 0;
}

  

posted on 2012-05-13 07:26  Try86  阅读(279)  评论(0)    收藏  举报