当前位置:网站首页>Leetcode 2001. Number of groups of interchangeable rectangles (brute force enumeration failed)
Leetcode 2001. Number of groups of interchangeable rectangles (brute force enumeration failed)
2022-06-10 03:57:00 【I'm not xiaohaiwa~~~~】
From... With a subscript 0 Start with a two-dimensional integer array rectangles To express n A rectangle , among rectangles[i] = [widthi, heighti] It means the first one i The width and height of a rectangle .
If two rectangles i and j(i < j) Have the same aspect ratio , These two rectangles Interchangeable . A more standardized statement is , Two rectangles satisfy widthi/heighti == widthj/heightj( Use real division instead of integer division ), These two rectangles Interchangeable .
Calculate and return rectangles How many of them are right Interchangeable rectangular .
Example 1:
Input :rectangles = [[4,8],[3,6],[10,20],[15,30]]
Output :6
explain : Press the subscript below ( from 0 Start ) List the pairing of interchangeable rectangles :
- rectangular 0 And rectangle 1 :4/8 == 3/6
- rectangular 0 And rectangle 2 :4/8 == 10/20
- rectangular 0 And rectangle 3 :4/8 == 15/30
- rectangular 1 And rectangle 2 :3/6 == 10/20
- rectangular 1 And rectangle 3 :3/6 == 15/30
- rectangular 2 And rectangle 3 :10/20 == 15/30
Example 2:
Input :rectangles = [[4,5],[7,8]]
Output :0
explain : There are no pairs of interchangeable rectangles .
Tips :
- n == rectangles.length
- 1 <= n <= 10^5
- rectangles[i].length == 2
- 1 <= widthi, heighti <= 10^5
Code:
class Solution {
public:
long long interchangeableRectangles(vector<vector<int>>& rectangles) {
long long res=0;
int size=rectangles.size();
for(int i=0;i<size;i++)
{
for(int j=i+1;j<size;j++)
{
vector<int>sub1=rectangles[i];
vector<int>sub2=rectangles[j];
if(sub1[0]*sub2[1]==(sub1[1]*sub2[0]))
{
res++;
}
}
}
return res;
}
};
边栏推荐
- QT中的QProgressBar+QPushButton+QMainwindow+QTmer+布局管理器+QTextCodec+QTextToSpeech
- SSTI(模板注入) ——(7)
- Some vulnerabilities and testing methods of security testing
- C# 11 新特性:列表模式匹配
- MySQL——安装
- [image detection - edge detection] image edge extraction based on PCNN with matlab code
- "Chinese characteristics" of Web3
- 汇编:代码示例
- Cultural and natural heritage day, mission airdrop
- Tailwind causes the button icon of antd not to be centered
猜你喜欢

【主流Nivida显卡深度学习/强化学习/AI算力汇总】

【MySQl】多表关联的几种方式和外键问题、多表查询与子查询

Dapr - what are the advantages of the microservice framework used by major manufacturers?

ACL 2022 | the latest hot research in NLP field, you must not miss it!

RPC practice and core principles - Advanced notes
![[L1, L2 and smooth L1 loss functions]](/img/c6/27eab1175766b77d4f030b691670c0.png)
[L1, L2 and smooth L1 loss functions]

How to customize ThreadPoolExecutor thread pool gracefully
![[actual combat] redis cluster (Part 2) - system version support](/img/dd/c4863d4c34ccc37dad9ed6d0b3413d.jpg)
[actual combat] redis cluster (Part 2) - system version support

汇编:关于函数完整流程的栈桢解析

【半监督分类】基于K-means和Label+Propagation的半监督网页分类
随机推荐
Google Earth Engine(GEE)——GPWv411:平均行政单位面积数据集
MySQL——约束条件
document editor
在线JSON转CSV工具
Dapr - what are the advantages of the microservice framework used by major manufacturers?
聊聊保证线程安全的10个小技巧
Quit smoking log_ 04 (day_09)
【TFLite, ONNX, CoreML, TensorRT Export】
SSTI(模板注入) ——(7)
C language question brushing series (II)
SSTI (template injection) - (8)
Preorder traversal binary tree
推特同意开放数据库供马斯克核查
为什么使用三层交换机
yolov5目标检测神经网络——损失函数计算原理
Is the online account opening channel reliable? Is it safe?
【主流Nivida显卡深度学习/强化学习/AI算力汇总】
[image detection - edge detection] image edge extraction based on PCNN with matlab code
[image fusion] Application of two-dimensional multi empirical mode decomposition in multi-scale image fusion with matlab code
[singleshotmultiboxdetector (SSD)