have a change: a cluster a=[a1,a2,… ,an] of unmistakable whole numbers from 1 to n. The length of the change n is odd.  You need to sort the change in expanding request. In one stage, you can pick any prefix of the change with an odd length and opposite it. Officially, if a=[a1,a2,… ,an], you can pick any odd number p among 1 and n, comprehensive, and set a to [ap,ap−1,… ,a1,ap+1,ap+2,… ,an].  Figure out how to sort

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Python

 

You have a change: a cluster a=[a1,a2,… ,an] of unmistakable whole numbers from 1 to n. The length of the change n is odd. 

You need to sort the change in expanding request. In one stage, you can pick any prefix of the change with an odd length and opposite it. Officially, if a=[a1,a2,… ,an], you can pick any odd number p among 1 and n, comprehensive, and set a to [ap,ap−1,… ,a1,ap+1,ap+2,… ,an]. 

Figure out how to sort a utilizing close to 5n2 inversions of the above kind, or establish that such a way doesn't exist. The quantity of inversions doesn't need to be limited. 

Information : Each test contains numerous experiments. The primary line contains the quantity of experiments t (1≤t≤100). Depiction of the experiments follows. The principal line of each experiment contains a solitary whole number n (3≤n≤2021; n is odd) — the length of the change. 

The subsequent line contains n particular whole numbers a1,a2,… ,an (1≤ai≤n) — the actual stage. 

It is ensured that the amount of n over all experiments doesn't surpass 2021. 

Yield :For each experiment, in case it's difficult to sort the given change in all things considered 5n2 inversions, print a solitary whole number −1. 

In any case, print a number m (0≤m≤5n2), indicating the quantity of inversions in your arrangement of steps, trailed by m whole numbers pi (1≤pi≤n; pi is odd), signifying the lengths of the prefixes of a to be turned around, in sequential request. Note that m doesn't need to be limited. In case there are different replies, print any

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY