What is Python's isinstance called in golang?

Starlight_ Glimmer 2020-11-17 21:08:09
python isinstance golang

Topic link

Brief introduction

Find the number of unordered triples with the same Manhattan distance between any two points .



First , There is a conclusion : On the plane to the point \((x,y)\) The Manhattan distance is \(d\) The trajectory of the point , In order to \((x,y)\) Centered ,\(2d\) For the diagonal square .( It's the quadrilateral in the graph \(BCDE\)

This should look better , When the dot is sliding on a square , Ordinate \(±1\), The abscissa is also \(±1\). To be more exact , Abscissa \(A\) far \(1\), The ordinate is away from \(A\) near \(1\), Abscissa \(A\) near \(1\), The ordinate is away from \(A\) far \(1\).

But the diamond is oblique , Not easy to do , So let's spin ,“ right ”, hold \((x,y)\) become \((x+y,x-y)\).

This is probably why many of the solutions are saying that it can be transformed into Chebyshev distance .


Another conclusion :\((x,y)\) Transform the coordinate system \(->(x+y,x-y)\), Manhattan distance in the original coordinate system = Chebyshev distance in the new coordinate system

Just a quick explanation :

At two o 'clock \((x1,y1),(x2,y2)\)

Manhattan distance in the original coordinate system \(=|x1-x2|+|y1-y2|\)

Chebyshev distance in the new coordinate system \(=max(|x1+y1-x2-y2|,|x1-y1-x2+y2|)=max(|x1-x2+y1-y2|,|x1-x2-(y1-y2)|)\)

Let's talk about it \(x1-x2\) and \(y1-y2\) The sign and absolute value of the .

Make \(x1-x2=m,y1-y2=n\)( It's easy to write

\(m,n\) Same number ,\(|m+n|=|m|+|n|,|m-n|=||m|-|n||\)

be aware , No matter what \(|m|,|n|\) How about the size relationship ,\(|m-n|=(|m|-|n|)/(|n|-|m|)\) It's all smaller than \(|m|+|n|\) Of , Obtain evidence .

\(m,n\) When there is a different sign ,\(|m+n|=||m|-|n||,|m-n|=|m|+|n|\), Empathy .

Another similar conclusion , I also add here ( This problem doesn't use ):\((x,y)->(\frac{x+y}2,\frac{x-y}2)\), Chebyshev distance of the original coordinates = Manhattan distance in new coordinates , Prove the same .

Of course , It's an algebraic way of understanding , I think it can be simpler in terms of Geometry .

It was said that , Square \(BCDE\) Is to meet the Manhattan distance for \(d\) Track of .

So if you put the trajectory right , Put every point on the square according to \((x,y)->(x+y,x-y)\) mapping ( Transform the coordinate system ), Draw one to \(2d\) For a square with a side length , And by geometric relations ( Look at the picture ) Easy to know , This square is to \(A\) Point Chebyshev distance is \(d\) The trajectory of the point .


A conditional triple must have two dots \(x\) or \(y\) The coordinates are the same .

If you first select two points that do not meet the above requirements \(A,B\)

It's marked out in the picture \(T,U\) It's the third eligible person spot , They all satisfy the above conditions .(\(A\) The point that meets the condition is with \(A\) The side length of the center is \(3\) The square of ,\(B\) Empathy , So the point satisfying the condition is the intersection of two square trajectories )( I'm a little bit messy


that , The qualified Sanyuan Group leader looks like this :

All the whole points on the line meet the conditions .

You can enumerate \(A,B\) spot , because \(A,B\) Of \(x/y\) The coordinates are the same , The complexity is \(O(n^3)\) Of , As for the calculation \(CD\) How many dots between , This can be prefixed and maintained .

\(x,y\) The coordinates are the same , however \(ABC,BCD,ABD,BDA\) It's going to be counted twice ( That is, the boundary points will be calculated repeatedly ), So in the second enumeration , It's OK not to include the boundary points .


In fact, there is no need to transform the coordinate system , It's OK to take the original oblique coordinates directly , It's just a little more troublesome to write about , And it's going to rotate in four directions , But you don't have to think about the middle deduction .

But if you've seen something like this , It will be much more convenient to do questions .

►Code View

using namespace std;
#define LL long long
#define N 305
#define DEL 100000
#define INF 0x3f3f3f3f
int rd()
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48); c=getchar();}
return f*x;
int n,ans;
char mp[N][N];
int a[N<<1][N<<1],s1[N<<1][N<<1],s2[N<<1][N<<1];
int main()
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i+j][i-j+n]=1;// To Chebyshev distance Prevent negative numbers Translation coordinates
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(a[i][j])// The first cow spot
for(int k=j+1;k<=n;k++)// The second cow spot And the first point i identical
int d=i+(k-j);
if(d<=n) ans+=s1[d][k]-s1[d][j-1];
if(d>=1) ans+=s1[d][k]-s1[d][j-1];
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=j+1;k<=n;k++)
int d=i+(k-j);
if(d<=n) ans+=s2[k-1][d]-s2[j][d];// We need to dig out the boundary points It's been calculated before
if(d>=1) ans+=s2[k-1][d]-s2[j][d];
return 0;
本文为[Starlight_ Glimmer]所创,转载请带上原文链接,感谢

  1. 利用Python爬虫获取招聘网站职位信息
  2. Using Python crawler to obtain job information of recruitment website
  3. Several highly rated Python libraries arrow, jsonpath, psutil and tenacity are recommended
  4. Python装饰器
  5. Python实现LDAP认证
  6. Python decorator
  7. Implementing LDAP authentication with Python
  8. Vscode configures Python development environment!
  9. In Python, how dare you say you can't log module? ️
  10. 我收藏的有关Python的电子书和资料
  11. python 中 lambda的一些tips
  12. python中字典的一些tips
  13. python 用生成器生成斐波那契数列
  14. python脚本转pyc踩了个坑。。。
  15. My collection of e-books and materials about Python
  16. Some tips of lambda in Python
  17. Some tips of dictionary in Python
  18. Using Python generator to generate Fibonacci sequence
  19. The conversion of Python script to PyC stepped on a pit...
  20. Python游戏开发,pygame模块,Python实现扫雷小游戏
  21. Python game development, pyGame module, python implementation of minesweeping games
  22. Python实用工具,email模块,Python实现邮件远程控制自己电脑
  23. Python utility, email module, python realizes mail remote control of its own computer
  24. 毫无头绪的自学Python,你可能连门槛都摸不到!【最佳学习路线】
  25. Python读取二进制文件代码方法解析
  26. Python字典的实现原理
  27. Without a clue, you may not even touch the threshold【 Best learning route]
  28. Parsing method of Python reading binary file code
  29. Implementation principle of Python dictionary
  30. You must know the function of pandas to parse JSON data - JSON_ normalize()
  31. Python实用案例,私人定制,Python自动化生成爱豆专属2021日历
  32. Python practical case, private customization, python automatic generation of Adu exclusive 2021 calendar
  33. 《Python实例》震惊了,用Python这么简单实现了聊天系统的脏话,广告检测
  34. "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system in Python
  35. Convolutional neural network processing sequence for Python deep learning
  36. Python data structure and algorithm (1) -- enum type enum
  37. 超全大厂算法岗百问百答(推荐系统/机器学习/深度学习/C++/Spark/python)
  38. 【Python进阶】你真的明白NumPy中的ndarray吗?
  39. All questions and answers for algorithm posts of super large factories (recommended system / machine learning / deep learning / C + + / spark / Python)
  40. [advanced Python] do you really understand ndarray in numpy?
  41. 【Python进阶】Python进阶专栏栏主自述:不忘初心,砥砺前行
  42. [advanced Python] Python advanced column main readme: never forget the original intention and forge ahead
  43. python垃圾回收和缓存管理
  44. java调用Python程序
  45. java调用Python程序
  46. Python常用函数有哪些?Python基础入门课程
  47. Python garbage collection and cache management
  48. Java calling Python program
  49. Java calling Python program
  50. What functions are commonly used in Python? Introduction to Python Basics
  51. Python basic knowledge
  52. Anaconda5.2 安装 Python 库(MySQLdb)的方法
  53. Python实现对脑电数据情绪分析
  54. Anaconda 5.2 method of installing Python Library (mysqldb)
  55. Python implements emotion analysis of EEG data
  56. Master some advanced usage of Python in 30 seconds, which makes others envy it
  57. python爬取百度图片并对图片做一系列处理
  58. Python crawls Baidu pictures and does a series of processing on them
  59. python链接mysql数据库
  60. Python link MySQL database