Code:
1 ImportJava.util.Scanner;2 3 Public classMain {4 Public Static voidMain (string[] args) {5Scanner sc =NewScanner (system.in);6 intn =sc.nextint ();7 intnum[]=New int[n];//array of user input8 intb[]=New int[n];//Copy num9 intc[]=New int[n];//Keep the minimum subscript (1th Small, 2nd small, 3rd small ...) )Ten One for(inti=0;i<n;i++){ Anum[i]=sc.nextint (); - } - for(inti=0;i<n;i++) the { -b[i]=Num[i]; - } - //num Sort Ascending + inttemp; - for(inti=0;i<n;i++){ + for(intj=i;j<n;j++){ A if(num[i]>Num[j]) { attemp=Num[j]; -num[j]=Num[i]; -num[i]=temp; - } - } - } in //find each minimum subscript - intI=0,j=0,k=0; to while(true){ + if(num[i]==B[j]) { -c[k]=J; thei++; *k++; $J=0;Panax Notoginseng } - Else{ theJ + +; + } A if(k==N) { the Break; + } - } $ //Calculation Results $ for(intm=0;m<n-1;m++){ - if(c[m]>c[m+1]){ -SYSTEM.OUT.PRINTLN (n-(m+2) +1); the Break; - }Wuyi } the } -}
Idea: The main is to find the law, I find a good long time, found the law.
Assuming that the array length n, the X-decimal position is in front of the x-1 small value position, the minimum number of operations is: n-x+1
Example:
(1): The array length is 4, the value is 19 7 8 25 respectively. Minimum number of operations: 4-3+1=2
(2): The array length is 6, the value is 19 8 7 9 10 25 respectively. Minimum number of operations: 6-2+1=5
For example (1), the minimum value is 7, the second is 8, and the third small is 19. 8 after 7, do not move 8,19 in 8 front, move 19,19 is the third small, so the number of operations: 4-3+1=2
For example (2), the minimum value is 7 and the second small is 8. Found 8 in front of 7, start moving 8,8 is the second small, so the number of operations: 6-2+1=5
Summary: As long as give me 10 seconds, I this programming problem score will get hands, alas ...
Through this online test, found that the knowledge of the front-end is too little to know, to engage in front-end, but also need to redouble efforts to supplement knowledge.
201,700 degree web front end intern Online Pen test