当前位置:网站首页>Li Kou daily question - Day 32 -1232 Dotted line
Li Kou daily question - Day 32 -1232 Dotted line
2022-07-01 18:47:00 【Chongyou research Sen】
2022.7.1 Did you brush the questions today ?
subject :
Given an array coordinates , among coordinates[i] = [x, y] , [x, y] The abscissa is x、 Ordinate for y The point of . Please judge , Whether these points belong to the same line in the coordinate system .
analysis :
Here are some two-dimensional arrays , You need to judge whether these two-dimensional arrays are on a straight line , But one thing to pay attention to , If you're going to find out y=kx+b To judge , There will be cases where the denominator is negative when the slope is divided !
Ideas : Using the slope formula
(y1-y0)/(x1-x0)=(yi-y0)/(xi-x0) Prevention and elimination 0, Transformed into a form of multiplication (y1-y0)*(xi-x0)==(x1-x0)*(yi-y0)
analysis :
1. Violent solution
class Solution {
public:
bool checkStraightLine(vector<vector<int>>& coordinates) {
for (auto i = 2; i < coordinates.size(); i++)
{
if ((coordinates[1][1]-coordinates[0][1])*(coordinates[i][0]-coordinates[0][0])!=(coordinates[i][1]-coordinates[0][1])*(coordinates[1][0]-coordinates[0][0]))
{
return false;
}
}
return true;
}
};
边栏推荐
- [CF1476F]Lanterns
- MySQL connection tools
- 1380. Lucky number in matrix / 1672 Total assets of the richest customers
- Lumiprobe Lumizol RNA 提取试剂解决方案
- [CF559E]Gerald and Path
- How to find the optimal learning rate
- The R language uses the tablestack function of epidisplay package to make statistical summary tables (descriptive statistics based on the grouping of target variables, hypothesis testing, etc.). If th
- D. Yet Another Minimization Problem
- Five degrees easy chain enterprise app is newly upgraded
- Find all missing numbers in the array
猜你喜欢
磁盘的基本知识和基本命令
A wonderful time to buy and sell stocks
Depth first search - DFS (burst search)
为什么独立站卖家都开始做社交媒体营销?原来客户转化率能提高这么多!
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Search 2D matrix 2
Data query language (DQL)
Lumiprobe non fluorescent alkyne EU (5-ethynyluridine)
用WPF写一款开源方便、快捷的数据库文档查询、生成工具
Solution: you can ping others, but others can't ping me
随机推荐
What if the reliability coefficient is low? How to calculate the reliability coefficient?
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
用WPF写一款开源方便、快捷的数据库文档查询、生成工具
Reading notes series "modern methods of C language programming" -- Chapter 2
Lumiprobe lumizol RNA extraction reagent solution
Write an open source, convenient and fast database document query and generation tool with WPF
Three.js学习-相机Camera的基本操作(了解向)
How to manage 1000 anchors by one person?
Operation of cmake under win
Memo - about C # generating barcode
Weekly recommended short videos: be alert to the confusion between "phenomena" and "problems"
Localization through custom services in the shuttle application
字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化
记一次 .NET 差旅管理后台 CPU 爆高分析
GameFramework食用指南
How to find the optimal learning rate
About enterprise middle office planning and it architecture microservice transformation
Popular science: what does it mean to enter the kernel state?
Lumiprobe非荧光炔烃丨EU(5-乙炔基尿苷)
Blue Bridge Cup real topic: the shortest circuit