Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问一对逆序数字是如何定义的? #1

Open
wenzhengzeng opened this issue Jun 11, 2020 · 2 comments
Open

请问一对逆序数字是如何定义的? #1

wenzhengzeng opened this issue Jun 11, 2020 · 2 comments

Comments

@wenzhengzeng
Copy link

请问逆序对是不是指当前状态和目标状态某两棋子相对顺序反了?每一对逆序棋子是不是不应重复考虑,如假设棋子1、2为一逆序对,那么在统计逆序对个数时,棋子1、2与棋子2、1是否算同一对,并不累加?代码中并没有考虑这一点,如当前状态为283164705,目标状态为123804765,那么实际上应该是4对逆序数字:1和2,1和3,1和8,3和8;而用代码中的写法算出来是6对:2和1,8和3,8和1,1和2,1和8,1和3,即1和2,1和8分别被视为了两对。

@wenzhengzeng
Copy link
Author

谢谢,我想问的是这个启发函数h
image
我在你的代码中看到的好像不是你说的那个逆序数的意思
image

@ConnoRLuv
Copy link
Owner

抱歉 我会错意了。你的理解应该是正确的,这里的代码存在问题。具体的要求是老师口述的,时间略久没有存留下来。我搜索了一下,相同题目也有人利用目标状态逆序数与当前状态逆序数之差的绝对值作为启发函数的,你也可以尝试一下。感谢指正

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants