当前位置:网站首页>LeetCode 447. Number of boomerangs (permutation and combination problem)
LeetCode 447. Number of boomerangs (permutation and combination problem)
2022-04-23 02:01:00 【Currybeefer】

In general, we need to find the combination of three points ,i,j,k, For i Come on ,j and k On i The distances must be equal .
Violent enumeration requires a triple cycle , So the time complexity is O(n^3) It's not worth it .
So we can think of the permutation and combination problem , The idea is to enumerate if i Fixed point , Filter out the distance and... From the remaining points i A collection of equal points .
Suppose you're away from i A distance of a A little n individual , So it's from n Choose two points in the order and i Combine , The permutation and combination problem ,An2.
Store a hash table with a distance of a Number of combinations , Add it up .
int numberOfBoomerangs(vector<vector<int>>& points)
{
int res=0;
for(int i=0;i<points.size();i++)
{
unordered_map<int,int> map;
for(int j=0;j<points.size();j++)
{
int dis=Distance(points[i],points[j]);
map[dis]++;
}
for(auto p=map.begin();p!=map.end();p++)
{
res+=p->second*(p->second-1);
}
}
return res;
}
int Distance(vector<int> a, vector<int> b)
{
int x=a[0]-b[0];
int y=a[1]-b[1];
return x*x+y*y;
}
版权声明
本文为[Currybeefer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220846113211.html
边栏推荐
- Virtual serial port function of j-link V9 using skills
- ESP32使用freeRTOS的消息队列
- [hands on learning] network depth v2.1 Sequence model
- When should I write unit tests? What is TDD?
- English abbreviation of role personal attribute
- CC2541的仿真器CC Debugger使用教程
- [experience tutorial] Alipay balance automatically transferred to the balance of treasure how to set off, cancel Alipay balance automatically transferred to balance treasure?
- 搭建网站是用物理机还是云主机好?
- BGP服务器在什么业务场景会被用到?
- Sqlserver data transfer to MySQL
猜你喜欢

J-Link RTT使用

2022 low voltage electrician examination questions and answers

What are the test steps of dynamic proxy IP?

浅析静态代理ip的三大作用。

What is a dial-up server and what is its use?

Esp32 message queue using FreeRTOS

J-link v9 使用技巧之虚拟串口功能

紫光国微财报一枝独秀 2021年净利润三位数增长靠什么

我国科学家揭示突破水稻产量瓶颈新机制

What business scenarios will the BGP server be used in?
随机推荐
Is CICC fortune a state-owned enterprise and is it safe to open an account
What is an API interface?
postman里面使用 xdebug 断点调试
What problems will you encounter when dialing VPS?
When should I write unit tests? What is TDD?
《维C中国》乡村助农暖人心第三站嘉宝果农场
2018 China Collegiate Programming Contest - Guilin Site J. stone game
2018 China Collegiate Programming Contest - Guilin Site J. stone game
Cc2541 emulator CC debugger tutorial
How to configure iptables to realize local port forwarding
世界读书日 | 技术人不要错过的好书(IT前沿技术)
What should I pay attention to when using proxy IP?
npm——配置淘宝镜像
Some tips for using proxy IP.
搭建网站是用物理机还是云主机好?
Digital collection platform settled in digital collection platform to develop SaaS platform of digital collection
揭秘被Arm编译器所隐藏的浮点运算
MySQL basic record
Error in face detection and signature of Tencent cloud interface
Under the pressure of sales, domestic mobile phones began to reduce prices, but they haven't put down their final face