hdu1432 Lining Up --判断点在一条线上的个数

来源:互联网 发布:北外网络教育多少钱 编辑:程序博客网 时间:2024/05/16 14:29

原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=1432


一:分析
给n个点,判断有多少个在一条线上。


二:AC代码
#define _CRT_SECURE_NO_DEPRECATE #include<iostream>#include<cmath>#include<algorithm>using namespace std;int a[705];int b[705];int n;int main(){while (~scanf("%d", &n) && n){for (int i = 0; i < n; i++)scanf("%d%d", &a[i], &b[i]);int ans = 0;for (int i = 0; i < n; i++){for (int j = i + 1; j < n; j++){int num = 0;for (int k = j + 1; k < n; k++){if ((a[i] - a[j])*(b[j] - b[k]) - (b[i] - b[j])*(a[j] - a[k]) == 0)num++;}ans = max(num, ans);}}printf("%d\n", ans + 2);}return 0;}







1 0
原创粉丝点击