博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2606 Rabbit hunt(我的水题之路——斜率最多)
阅读量:4069 次
发布时间:2019-05-25

本文共 2297 字,大约阅读时间需要 7 分钟。

Rabbit hunt
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6159   Accepted: 3008

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 the both. But killing three or more rabbits in one shot is much more difficult task. To be the best hunter in the world one should be able to kill the maximal possible number of rabbits. Assume that rabbit is a point on the plane with integer x and y coordinates. Having a set of rabbits you are to find the largest number K of rabbits that can be killed with single shot, i.e. maximum number of points lying exactly on the same line. No two rabbits sit at one point.

Input

An input contains an integer N (2<=N<=200) specifying the number of rabbits. Each of the next N lines in the input contains the x coordinate and the y coordinate (in this order) separated by a space (-1000<=x,y<=1000).

Output

The output contains the maximal number K of rabbits situated in one line.

Sample Input

67 1228 1399 15610 17311 190-100 1

Sample Output

5

Source

有n个点,问最多有多少个点共线。
直接copy的1118的代码。解法详见:
注意点:
1)两个题目的结束条件不一样。(1OLE)
代码(1AC 1OLE):
#include 
#include
#include
#include
#include
using namespace std;int aid[1000][2];float xielv[1000];int main(void){ int i, j, k; int max, tmp; int n; while (scanf("%d", &n) != EOF){ memset(aid, 0, sizeof(aid)); for (i = 0; i < n; i++){ scanf("%d%d", &aid[i][0], &aid[i][1]); } max = 2; for (i = 0; i < n - 1; i++){ for (j = i + 1, k = 0; j < n; j++){ if (aid[j][0] == aid[i][0]){ xielv[k++] = 32767; } else{ xielv[k++] = (float)(aid[j][1] - aid[i][1]) / (float)(aid[j][0] - aid[i][0]); } } sort(xielv, xielv + k); for (j = 1, tmp = 2; j <= k; j++){ if (xielv[j] == xielv[j - 1]){ tmp ++; if (tmp > max){ max = tmp; } } else{ tmp = 2; } } } printf("%d\n", max); } return 0;}

转载地址:http://hooji.baihongyu.com/

你可能感兴趣的文章
ceph 故障分析(backfill_toofull)
查看>>
ceph 故障解决备忘
查看>>
更改 ceph journal 位置
查看>>
docker private registry using rados beckend
查看>>
使用 docker 后出现的网络异常现象
查看>>
ceph ( requests are blocked ) 异常解决方法
查看>>
ceph 报警 [ low disk space] 解决
查看>>
python 调用 lvs 脚本 [备忘]
查看>>
openstack 命令行管理二十一 - 云盘管理 (备忘)
查看>>
docker 文件位置[备忘]
查看>>
rhel7 kickstart 参考[备忘]
查看>>
DNS请求分析
查看>>
docker - 资源限制
查看>>
puppet 配置 1. 服务器, 客户端配置说明
查看>>
puppet 配置 2 模块
查看>>
puppet 配置 3. 资源
查看>>
打造自己的 DockerImage
查看>>
rhel7.2 优化技巧
查看>>
megacli 划分, 删除 raid 方法备忘
查看>>
ceph - crush map 与 pool
查看>>