Original question :
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, when validating the n=3, we need to calculate 3, 5, 8, 4, 2, 1, then when we verify the n=5, 8, 4, 2, we can directly determine the authenticity of Karaz conjecture, and do not need to repeat the calculation, because this 4 number has been in the validation of 3, we call 5, 8, 4, 2 is the number that is 3 "covered". We call a number N in a series A "key number" if 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, the 1th line 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 numbers.
output format: the output of each test case occupies 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
My understanding:
This problem is mainly the analysis of test instructions, to clarify the definition of "key number",
Is that the number does not appear in the process of judging whether a number in the array satisfies the Karaz conjecture.
Figure this out, then it's easy.
First find out all the numbers that appear in the process of judging a certain number to satisfy the conjecture
And then let the number in the original array and the previous step appear in all the number one by one comparison,
Try to remove the number from the array as long as the number of identical matches appears in the array.
The final sort output is ok
Code
1#include <stdio.h>2#include <malloc.h>3 4 voidSortint*,int );5 intMain ()6 {7 int*A;8 intn,i,t,j;9scanf"%d",&n);TenA= (int*)malloc(nsizeof(int));//Dynamic Request Array Space One for(i=0; i<n;i++) A { -scanf"%d",&a[i]); - } the for(i=0; i<n;i++) - { -t=A[i]; - if(t==0) + Continue;//If you encounter 0 of the items in the array, skip - while(t!=1) + { A if(t%2==0) atT/=2; - Else -T= (3*t+1)/2; - for(j=0; j<n;j++)//comparison of all numbers in an array with the number of occurrences in an operation - { - if(a[j]==t)//if the array has the same number as the operation procedure, change the number in the array to 0 in { -a[j]=0; to Break;//because the input array is not the same number, there is no case of multiple matches, and a match can be found to jump out to save memory and reduce run time. + } - } the * } $ Panax Notoginseng } -Sort (a,n);//Sort the for(i=0;a[i]>0; i++) + { Aprintf"%d%s", a[i],a[i+1]>0?" ":""); the } + } - voidSortint*p,intK//Sort $ { $ inti,j,temp; - for(i=0; i<k;i++) - for(j=i+1; j<k;j++) the { - Wuyi if(p[i]<P[j]) the { -temp=P[i]; Wup[i]=P[j]; -p[j]=temp; About } $ } -}
Pat B true Title 1005. Continuation (3n+1) conjecture (25) (Problem solving)