POJ2606 Rabbit hunt

问题链接:POJ2606 Rabbit hunt。

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

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

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

这个问题与POJ1118 HDU1432 Lining Up基本上相同,只是输入数据格式略有不同。

AC的C语言程序如下:

/* POJ2606 Rabbit hunt */

#include <stdio.h>

#define MAXN 200

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

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

    scanf("%d", &n);

    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-08-02 02:50:40

POJ2606 Rabbit hunt的相关文章

POJ 2606 Rabbit hunt【简单几何】

Rabbit hunt Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8015   Accepted: 3993 Description A good hunter kills two rabbits with one shot. Of course, it can be easily done since for any two points we can always draw a line containing t

Lining Up Rabbit hunt poj 1118 poj 2606 点共线问题。

思路:首先把所有点按照坐标排序,然后以每一个点为基准点,计算其他点与这个点连线的斜率,将所有斜率排序后求最多的相同的斜率数即可. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <string> 7 #include <vector> 8 #

hdu 5030 Rabbit&#39;s String(后缀数组&amp;二分)

Rabbit's String Time Limit: 40000/20000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 288    Accepted Submission(s): 108 Problem Description Long long ago, there lived a lot of rabbits in the forest. One day, the

HDU4057 Rescue the Rabbit(AC自动机+状压DP)

题目大概是给几个DNA片段以及它们各自的权值,如果一个DNA包含某个片段那么它的价值就加上这个片段的权值,同时包含多个相同DNA片段也只加一次,问长度l的DNA可能的最大价值. 与HDU2825大同小异. dp[i][j][S]表示长度i(自动机转移i步).后缀状态为自动机第j个结点.包含的DNA片段为集合S 的DNA最大价值 dp[0][0][0]=0 我为人人转移,从dp[i][j][S]向ATCG四个方向更新dp[i+1][j'][S'] 注意的是要用滚动数组,不然要开上百兆数组. 用滚动

HDU1849 Rabbit and Grass()

用异或看取得的值是否为0判断 思想换没搞懂 #include<stdio.h> int main() { int ans,n,a; while(scanf("%d",&n),n){ ans=0; while(n--){ scanf("%d",&a); ans=ans^a; } if(ans==0) printf("Grass Win!\n"); else printf("Rabbit Win!\n"

HDU 4057 Rescue the Rabbit (AC自动机+DP)

http://acm.hdu.edu.cn/showproblem.php?pid=4057 Rescue the Rabbit Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1482    Accepted Submission(s): 430 Problem Description Dr. X is a biologist,

HDU - 1849 - Rabbit and Grass

先上题目: Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2097    Accepted Submission(s): 1579 Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛

13杭州区域赛现场赛Rabbit Kingdom(树状数组+离线)

题意:给你一个长度数列,再给你m个询问(一个区间),问你在这个区间里面有多少个数与其他的数都互质. 解题思路:你看这种类型的题目都可以肯定这是 离线+树状数组(线段树).主要就是他的更新信息.这里我的处理是先把1-200000(每个数的范围)数里面所有的质因子求出来.然后从后往前遍历数组.会出现以下几种情况 1.a[k]的质因子在后面出现过而[更新标记] 和[被更新标记] 都为假 2.a[k]的质因子在后面出现过的那个位置 I   [更新标记]为 真 . 3.a[k]的质因子在后面出现过且那个位

转化为用欧几里得算法判断互质的问题D - Wolf and Rabbit

Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into