当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
【木马免杀】
阿里巴巴政委体系-第五章、阿里政委体系建设
Shell编程之循环语句
云图说丨初识华为云微服务引擎CSE
ECCV 2022 Oral | 满分论文!视频实例分割新SOTA: IDOL
Protobuf Grpc使用异常 类型有未导出的方法,并且是在不同的软件包中定义
Jingdong cloud released a new generation of distributed database StarDB 5.0
Teach you to locate online MySQL slow query problem hand by hand, package teaching package meeting
从腾讯阿里等大厂出来创业搞 Web3、元宇宙的人在搞什么
安装anaconda并创建虚拟环境
随机推荐
MVC vs MVP
Cobalt Strike (CS) 逆向初探
Introduction to Cosine Distance
pg_memory_barrier_impl in Postgresql and C's volatile
JS 内置构造函数 扩展 prototype 继承 借用构造函数 组合式 原型式creat 寄生式 寄生组合式 call apply instanceof
边缘盒子+时序数据库,美的数字化平台 iBuilding 背后的技术选型
那些年我写过的语言
花 30 美金请 AI 画家弄了个 logo,网友:画得非常好,下次别画了!
关于2022年度深圳市技术攻关重大项目的申报通知
软件测试回归案例,什么是回归测试?
net-snmp编译报错:/usr/bin/ld: cannot find crti.o: No such file or directory
if/else或switch替换为Enum
安装radondb mysql遇到问题
安装anaconda并创建虚拟环境
盘点在线帮助中心对企业能够起到的作用
MySQL基础
京东云发布新一代分布式数据库StarDB 5.0
Reveal how the five operational management level of hundreds of millions of easily flow system
虚拟机vmware设置nat模式上网
按需视觉识别:愿景和初步方案