POJ1118 HDU1432 Lining Up

问题链接:POJ1118 HDU1432 Lining Up

题意简述:输入n,输入n个整数对,即n个坐标点,问最多共线点数是多少。

问题分析:用暴力法解决这个问题,好在计算规模不算大。

程序中,判断共线时,使用的是乘法,没有用除法,可以保证精确的计算结果。

AC的C语言程序如下:

/* POJ1118 HDU1432 Lining Up */

#include <stdio.h>

#define MAXN 700

struct {
    int x, y;
} p[MAXN];      /* point */

int main(void)
{
    int n, ans, max, i, j, k;

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

        ans = 2;
        for(i=0; i<n; i++)
            for(j=i+1; j<n; j++) {
                max = 2;
                for(k=j+1; k<n; k++)
                    if ((p[j].x - p[i].x)*(p[k].y - p[j].y) == (p[j].y - p[i].y)*(p[k].x - p[j].x))
                        max++;
                if(max > ans)
                    ans = max;
            }

        printf("%d\n", ans);
    }

    return 0;
}
时间: 2024-12-22 23:37:08

POJ1118 HDU1432 Lining Up的相关文章

UVALive5379 UVA270 Lining Up

Regionals 1994 >> North America - East Central NA 问题链接:UVALive5379 UVA270 Lining Up. 题意简述:输入n,输入n个整数对,即n个坐标点,问最多共线点数是多少. 问题分析:用暴力法解决这个问题,好在计算规模不算大. 程序中,判断共线时,使用的是乘法,没有用除法,可以保证精确的计算结果. 特别需要说明的是,这个问题虽然与POJ1118 HDU1432 Lining Up是相同的问题,但是数据输入格式不一样,需要特别处

POJ2606 Rabbit hunt

问题链接:POJ2606 Rabbit hunt. 题意简述:输入n,输入n个整数对,即n个坐标点,问最多共线点数是多少. 问题分析:用暴力法解决这个问题,好在计算规模不算大. 程序中,判断共线时,使用的是乘法,没有用除法,可以保证精确的计算结果. 这个问题与POJ1118 HDU1432 Lining Up基本上相同,只是输入数据格式略有不同. AC的C语言程序如下: /* POJ2606 Rabbit hunt */ #include <stdio.h> #define MAXN 200

POJ2708 Linearity

问题链接:POJ2708 Linearity. 题意简述:输入n,输入n个整数对,即n个坐标点,问最多共线点数是多少. 问题分析:用暴力法解决这个问题,好在计算规模不算大. 程序中,判断共线时,使用的是乘法,没有用除法,可以保证精确的计算结果. 这个问题与POJ1118 HDU1432 Lining Up基本上相同,只是输入数据格式略有不同. AC的C语言程序如下: /* POJ2708 Linearity */ #include <stdio.h> #define MAXN 1000 str

[POJ1118]Lining Up

Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24071   Accepted: 7564 Description "How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was not facing an easy task. She had to drop packages at specific poin

Hdoj 1432 Lining Up 【叉积】

Lining Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1094    Accepted Submission(s): 307 Problem Description ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot

Lining Up(在一条直线上的最大点数目,暴力)

Lining Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1274    Accepted Submission(s): 366 Problem Description ``How am I ever going to solve this problem?" said the pilot.  Indeed, the pilo

uva 270 Lining Up (几何)

uva 270 Lining Up ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was not facing an easy task. She had to drop packages at specific points scattered in a dangerous area. Furthermore, the pilot could only fly over the a

uva270 - Lining Up(暴力)

题目:uva270 - Lining Up 解题思路:对于每个点都计算一下,它与其他点的斜率,这样就可以判断与这个点在同一条直线的点.每个点都这样做,维护最大值就可以了. 注意斜率不存在的情况. 找相同斜率的时候用了multiset. 代码: #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <set> using namespace

POJ 1018 &amp; HDU 1432 Lining Up 【简单几何】

Lining Up Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24786   Accepted: 7767 Description "How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was not facing an easy task. She had to drop packages at spe