Sgu139help needed! Determine whether there is a solution for the 15th digital, and determine whether there is a deduction for the n digital.

Source: Internet
Author: User

This is the case. You need to determine whether there is a solution for the 15th digital.

I won't. I found this method.

Store 16 numbers in one-dimensional arrays in order of appearance,

Then accumulate the number of reverse pairs of each number,

Add the distance from 0 to the final state of Manhattan to get a number X.

Due to the final state, the number of Reverse Order pairs for the entire graph is 15,

Is an odd number, so if X is also an odd number,

Then there will be solutions for this 15 digital,

Otherwise, no solution is available.

All other digital products follow this method,

My code is as follows:

# Include <iostream> using namespace STD; int main () {int map [16], ANS = 0; For (INT I = 0; I <16; I ++) {scanf ("% d", & map [I]); If (! Map [I]) ans + = 6-i % 4-I/4; for (Int J = 0; j <I; j ++) if (Map [J]> map [I]) ans ++;} If (ANS & 1) printf ("yes"); elseprintf ("no ");}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.