Zoj 1201 Inversion

Source: Internet
Author: User

Zoj 1201 Inversion

P 5 9 1 8 2 64 7 3

I 2 3 6 4 0 22 1 0

I think this is a problem on the Internet, but I am really painstaking ~ So I need to write down my own well-behaved methods, which is better than none ~

The conversion from P to I is very simple. Find the number "1" in P. There are two numbers on the left of P, so the first number of I is 2, and so on ~

I to P conversion, key! For example, if the number 3 in I indicates that there are three numbers in front of 2 that are larger than him, then we need to see if the number 1 is in front of him, if it is in front of him or in its position (less than or equal to), the position of this number will be pushed back to a unit, but it is not enough to check it again, for example, for the 5th digits in I, it must be checked four times so that it has a sufficient opportunity to push back each digit before him. For example, the number "1" in I indicates the position of 8 in P, that is, subscript 3. At this time, the previous positions of 2, 3, 6, 4, 0, and 2 have been changed
2, 4, 8, 6, 0, 5, and 7. Then, when 1 encounters 0, it turns to 2, and then throws 0 to the array of numbers that have been determined by the definition. The second time, 2. When 2 is changed to 3, check it again several times, but there are no numbers smaller than or equal to 3, and 3 is no longer added, SO 3 is the subscript of number 8.

Code:

# Include <stdio. h> int main () {int I, j, n, m, K, G, n, a [1000], B [1000], L, C [1000], x, F, R, S [1000], Z; char t; for (I = 1; I ++) {scanf ("% d", & N ); if (n = 0) break; getchar (); scanf ("% C", & T); For (j = 0; j <= N-1; j ++) {scanf ("% d", & A [J]);} If (t = 'P') {for (j = 0; j <= N-1; j ++) {for (k = 0; k <= N-1; k ++) {if (a [k] = J + 1) break;} m = 0; for (G = 0; G <= K; G ++) {if (a [g]> J + 1) m ++;} If (J! = 0) printf (""); printf ("% d", m);} printf ("\ n");} If (t = 'I ') {for (j = 0; j <= N-1; j ++) {x = 1; F = 0; while (x <= J + 1) {for (G = 0; G <= J-1; G ++) {r = 1; for (Z = 0; Z <= F-1; Z ++) {If (G = s [Z]) {r = 0; break ;}} if (a [g] <= A [J] & R = 1) {s [f] = g; A [J] ++; // push the corresponding numeric subscript F ++ ;}} x ++ ;} B [A [J] = J + 1;} For (j = 0; j <= N-2; j ++) {for (k = J + 1; k <= N-1; k ++) {if (a [J]> A [k]) {L = A [k]; A [k] = A [J]; A [J] = L ;}}for (j = 0; j <= N-1; j ++) {If (J! = 0) printf (""); printf ("% d", B [A [J]) ;}} return 0 ;}

 

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.