uva270

来源:互联网 发布:mysql查看表锁定 编辑:程序博客网 时间:2024/06/06 10:46

题目大意:
找出一组数据红在同一个直线上的最多的点的个数

思路:去求斜率
代码:

#include <iostream>using namespace std;#include <cstring>#include <stdio.h>#include <algorithm>struct node {    float x,y;}n[705];int num;double nn[705];int main() {    int N,count1;    char str[100];    int _max;    int j,k,t,p,q,l;    scanf("%d",&N);//  getchar();    cin.get();    cin.get();    while(N--) {    //  printf("1");        int i = 0;        num = 0;//      count1 = 1;        _max = 0;        while(gets(str)) {            if(!str[0]) break;        //  n[i].x =atof(str[0]);        //  n[i].y =atof(str[1]);        sscanf(str,"%f%f",&n[i].x,&n[i].y);                 num++;            i++;        //  cout << str <<endl;        }    //  printf("%d ",num);        for( i = 0 ; i < num; i++) {            memset(nn,0,sizeof(nn));            for( j = 0,k = 0; j < num; j++) {                 if(i == j)                     continue;                nn[k++] = (n[j].y - n[i].y) / (n[j].x - n[i].x);            }            sort(nn,nn+k);            for( q = 0 ; q < num - 1; q++) {                for( k = q ,l = q + 1,t = 2; ; k++,l++)                                     if(nn[k] == nn[l]) {            //      printf("%f %d " ,nn[k],t);                    t++; // t == 2的原因是此时两个nn需要三组数据如果相等t=3                }                else                    break;            if(t > _max)                _max = t;        //  printf("%d ",t);            }        }        cout << _max<<endl;        if(N)            cout << endl;    }    return 0;}
0 0
原创粉丝点击