Title Requirements for:
Caraz (Callatz) conjecture:
For any of the natural numbers n, if it is an even number, cut it half off, and if it is odd, cut (3n+1) half. This has been repeatedly cut down, and finally must be in a certain step to get n=1. When we verify the Caraz conjecture, in order to avoid repeated computations, we can record the number of times encountered in the recursion process. For example, when n=3 is validated, we need to compute 3, 5, 8, 4, 2, 1, when we to n=5, 8, 4, 2 to verify the time, we can directly determine the authenticity of the Caraz conjecture, and do not need to repeat the calculation, because the 4 number has been in the validation of 3 encountered, we call 5, 8, 4, 2 is the number of 3 "overlays". We call a number N in a series as "critical", if n cannot be overwritten by other numbers in the series.
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 repeat the remaining numbers. Your task is to find these key numbers and output them in order from big to small.
input Format: Each test entry contains 1 test cases, line 1th gives a positive integer k (<100), and line 2nd gives the value of K-distinct positive integer n (1<n<=100), separated by a space between the digits.
output format: the output of each test case occupies one row, outputting key numbers in order from large to small. Numbers are separated by 1 spaces, but there are no spaces after the last number in a row.
Input Sample:
6
3 5 6 7 8 11
Output Sample:
7 6
The code is as follows:
<span style= "FONT-SIZE:14PX;"
> Import Java.util.ArrayDeque;
Import java.util.ArrayList;
Import Java.util.Deque;
Import java.util.List;
Import Java.util.Queue;
Import Java.util.Scanner;
Import Java.util.SortedSet;
Import Java.util.TreeSet; public class PAT1005 {public static void main (string[] args) {//TODO auto-generated method stub Scanne
R scanner = new Scanner (system.in);
int Numsize=scanner.nextint ();
Arraydeque<integer> newarraydeque=new arraydeque<integer> ();
Arraydeque<integer> closearraydeque=new arraydeque<integer> ();
int i; while (Scanner.hasnext ()) {//Read the keyboard input value for (i = 0; i < numsize; i++) {Newarraydeque.add (Scann
Er.nextint ());
} if (i>=numsize) {break;
} int temp;
for (Integer integer:newarraydeque) {//to deposit non-critical numbers in Closearraydeque Temp=integer; while (temp!=1) {if (temp%2==0) {TEMP=TEMP/2;
if (Newarraydeque.contains (temp)) {Closearraydeque.add (temp);
}}else {temp= (temp*3+1)/2;
if (Newarraydeque.contains (temp)) {Closearraydeque.add (temp); }}} sortedset<integer> sortedset=new treeset<integer> ();
SortedSet is used to hold the critical number for (integer integer:newarraydeque) {if (!closearraydeque.contains (integer)) {
Sortedset.add (integer);
} int[] Leftint=new int[sortedset.size ()];
int J=sortedset.size ()-1;
for (Integer integer:sortedset) {Leftint[j]=integer;
j--; for (int j2 = 0; J2 < leftint.length; j2++) {//output critical number in order from large to small if (j2==leftint.length-1) {Sy
Stem.out.println (Leftint[j2]);
}else {System.out.print (leftint[j2]+ ""); {}}}} </span>
The above is the entire content of this article, I hope to help you learn.