当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
1161 最大层内元素和——Leetcode天天刷【BFS】(2022.7.31)
阿里巴巴政委体系-第九章、阿里政委启示录
Teach you to locate online MySQL slow query problem hand by hand, package teaching package meeting
Shell编程之循环语句
Internet Download Manager简介及下载安装包,IDM序列号注册问题解决方法
Shell programming loop statement
CS免杀姿势
建模该从哪一步开始?给你分析,给零基础的你一些学习建议
Solution for no navigation bar after Word is saved as PDF
盘点在线帮助中心对企业能够起到的作用
随机推荐
JS 内置构造函数 扩展 prototype 继承 借用构造函数 组合式 原型式creat 寄生式 寄生组合式 call apply instanceof
Standard C language learning summary 11
relocation R_X86_64_PC32 against,/usr/bin/ld: final link failed: Bad value
【木马免杀】
按需视觉识别:愿景和初步方案
X86 function call model analysis
Unity gets the actual coordinates of the ui on the screen under the canvas
如何理解即时通讯开发移动网络的“弱”和“慢”
「学习笔记」高斯消元
Interview Blitz: What Are Sticky Packs and Half Packs?How to deal with it?
软件测试技术之如何编写测试用例(3)
Kettle 读取 Excel 数据输出到 Oracle 详解
Matlab论文插图绘制模板第42期—气泡矩阵图(相关系数矩阵图)
Unity获取canvas 下ui 在屏幕中的实际坐标
阿里二面:多线程间的通信方式有几种?举例说明
Climbing Stairs (7/30)
数据驱动的软件智能化开发| ChinaOSC
Network protocol-TCP, UDP difference and TCP three-way handshake, four wave
力扣刷题之爬楼梯(7/30)
【leetcode】剑指 Offer II 008. 和大于等于 target 的最短子数组(滑动窗口,双指针)