当前位置:网站首页>149. The largest number on a straight line, and check the set
149. The largest number on a straight line, and check the set
2022-08-03 19:41:00 【Mr Gao】
给你一个数组 points ,其中 points[i] = [xi, yi] 表示 X-Y 平面上的一个点.求最多有多少个点在同一条直线上.
示例 1:
输入:points = [[1,1],[2,2],[3,3]]
输出:3

示例 2:
输入:points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
输出:4

The blogger is also the first time to use the method of concatenating collections,I think it's really amazing,This method should solve many difficult problems,But to use it requires us to do some more applications:
解题代码如下:
int find(int x,int *p){
while(x!=p[x]){
x=p[x];
}
return x;
}
int maxPoints(int** points, int pointsSize, int* pointsColSize){
int p[pointsSize];
int i,j;
int max=0;
int cei[pointsSize][2];
for(i=0;i<pointsSize;i++){
printf("||");
int cur=0;
for(j=i+1;j<pointsSize;j++){
cei[cur][0]=points[i][0]-points[j][0];
cei[cur][1]=points[i][1]-points[j][1];
cur++;
}
// printf("cur %d |",cur);
int hash[pointsSize];
for(j=0;j<cur;j++){
p[j]=j;
}
for(j=0;j<cur;j++){
hash[j]=0;
for(int k=j+1;k<cur;k++){
if(cei[k][0]*cei[j][1]-cei[k][1]*cei[j][0]==0){
p[k]=j;
}
}
}
for(j=0;j<cur;j++){
max=fmax(max,++hash[find(j,p)]);
// printf("%d %d |",find(j,p),hash[find(j,p)]);
}
}
printf("max %d ",max);
return max+1;
}
边栏推荐
- Calculation of the array serial number of Likou brush questions (one question per day 7/28)
- 网络协议-TCP、UDP区别及TCP三次握手、四次挥手
- Word另存为PDF后无导航栏解决办法
- 「游戏建模干货」建模大师几步操作,学习经典,赶紧脑补一下吧
- ERROR: You don‘t have the SNMP perl module installed.
- ECCV2022 | 用于视频问题回答的视频图Transformer
- 关于2022年度深圳市技术攻关重大项目的申报通知
- 读取 resources 目录下的文件路径的九种方式,你知道多少?
- 开源生态研究与实践| ChinaOSC
- C中的数据存储
猜你喜欢
随机推荐
Handler 源码解析
FreeRTOS中级篇
Network protocol-TCP, UDP difference and TCP three-way handshake, four wave
基于移动GIS的环保生态管理系统
揭秘5名运维如何轻松管理数亿级流量系统
Protobuf Grpc使用异常 类型有未导出的方法,并且是在不同的软件包中定义
面试突击:什么是粘包和半包?怎么解决?
机器学习中专业术语的个人理解与总结(纯小白)
关于2022年度深圳市技术攻关重大项目的申报通知
docker mysql 容器中执行mysql脚本文件并解决乱码
阿里巴巴政委体系-第九章、阿里政委启示录
【QT】入门心法
The addition and subtraction of the score of the force deduction brush question (a daily question 7/27)
Matlab论文插图绘制模板第42期—气泡矩阵图(相关系数矩阵图)
1-php学习笔记之数据类型
Solution for no navigation bar after Word is saved as PDF
那些年我写过的语言
「学习笔记」高斯消元
力扣刷题之数组序号计算(每日一题7/28)
Postgresql source code (64) Query execution - data structure and execution process before submodule Executor (2) execution









