Karaz (Callatz) conjecture has been given a description in 1001. In this subject, the situation is slightly more complicated.
When we verify Karaz conjecture, in order to avoid repetition, we can record each number that is encountered in the recursive process. For example, ton= 3 for verification, we need to calculate 3, 5, 8, 4, 2, 1, when we are < Span class= "Strut bottom" >n= 5, 8, 4, 2 for verification, you can directly determine the authenticity of the Karaz conjecture, and do not need to repeat the calculation, because these 4 numbers have been in the verification of the time of 3, we call 5, 8, 4, 2 is 3 "covered" number. We call a number in a series n for "critical number" if < Span class= "katex-html" >< Span class= "Mord mathit" >n cannot be overridden by other numbers in the sequence.
Now given a series of numbers to be validated, we just need to validate a few of the key numbers, so we don't have to re-validate the remaining numbers. Your task is to find these key numbers and output them in order from large to small.
Input Format:
Each test input contains 1 test cases, and line 1th gives a positive integerK<100), 2nd Line gives k a distinct positive integer to be verified n ( 1 <n≤100), separated by a space between the numbers.
output Format:
The output for each test case takes one row, and the key numbers are output in order from large to small. The number is separated by 1 spaces, but there is no space after the last digit in a row.
Input Sample:
63 5 6 7 8 11
Sample output:
7 6
Analysis:
Iterate through the given list, removing the number of overlays from the list
The remaining number can be sorted
PS: If it's easier to use a collection
1 //C + +2#include <iostream>3 using namespacestd;4 5 intMain () {6 intN;7Cin>>N;8 intArr[n];9 for(intI=0; i<n;i++)TenCin>>Arr[i]; One for(intI=0; i<n;i++){ A if(arr[i]==0) - Continue; - inttmp=Arr[i]; the while(tmp!=1){ - if(tmp%2) -Tmp= (tmp*3+1)/2; - Else +Tmp/=2; - for(intj=0; j<n;j++){ + if(arr[j]==tmp) { Aarr[j]=0; at Break; - } - } - } - } - intFlag; in for(intI=0; i<n-1; i++){ -flag=1; to for(intj=0; j<n-i-1; j + +){ + if(arr[j]<arr[j+1]){ - inttmp=Arr[j]; thearr[j]=arr[j+1]; *arr[j+1]=tmp; $flag=0;Panax Notoginseng } - } the if(flag) + Break; A } the for(intI=0; arr[i]!=0; i++){ + if(i) -cout<<' '; $cout<<Arr[i]; $ } - return 0; -}
pat-Serie B-1005 continuation (3n+1) conjecture