uva270

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

思路:去求斜率
代码:

#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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值