(Relax ST1.14)POJ 1118 Lining Up(与POJ 2606差不多)


#include <iostream>
#include <cstdio>

using namespace std;

const int maxn = 1005;

struct Point{
	int x;
	int y;
}p[maxn];


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

    	int j,k;
    	int temp;
    	int Max = -100;
    	for(i = 0 ; i < n ; ++i){
    		for(j = i+1 ; j < n ; ++j){
    			temp = 0;
    			for(k = j+1 ; k < n ; ++k){
    				int a = (p[i].x - p[k].x)*(p[j].y - p[k].y);
    				int b = (p[i].y - p[k].y)*(p[j].x - p[k].x);

    				if(a == b){//如果三个点共线,则他们的斜率相同...
    					temp++;
    				}
    			}

    			Max = (Max > temp)?Max:temp;
    		}
    	}


    	printf("%d\n",Max+2);
    }

    return 0;
}




你可能感兴趣的:((Relax ST1.14)POJ 1118 Lining Up(与POJ 2606差不多))