1005 continue (3n+1) conjecture (25 points)

Callatz conjecture has been described in 1001. In this subject, the situation is a little complicated.

When we verify the karatz conjecture, in order to avoid repeated calculation, we can record every number encountered in the recursive process. For example, when verifying n=3, we need to calculate 3, 5, 8, 4, 2 and 1. When verifying n=5, 8, 4 and 2, we can directly determine the authenticity of karaz conjecture without repeated calculation, because these four numbers have been encountered when verifying 3. We call 5, 8, 4 and 2 "covered" by 3. We call a number N in a sequence "key number", if n cannot be covered by other numbers in the sequence.

Now, given a series of numbers to be verified, we only need to verify several key numbers, so we don't have to verify the remaining numbers again. Your task is to find these key numbers and output them in descending order.

Input format:

Each test input contains one test case. The first line gives a positive integer k (< 100), and the second line gives the values of K different positive integers n (1 < n ≤ 100) to be verified. The numbers are separated by spaces.

Output format:

The output of each test case occupies one line, and the key numbers are output in order from large to small. Numbers are separated by a space, but there is no space after the last number in a line.

Input example:

6

3 5 6 7 8 11

No blank lines at the end

Output example:

7 6

No blank lines at the end

To be honest, this idea is quite simple, but I didn't have a mind at the beginning, so I wasted a long time,

With sincere advice, you still have to study in a quiet place

Idea:

It is to calculate these numbers once. If there is the number in the input array in the calculation process, delete the number in the array

(or mark it, but there seems to be an error in my mark, that is, it is marked as 1. When there is 1 in the input array, some problems will occur, so I have an error here, and there is a point that can't pass.)

Then sort it at last.

// #include<stdio.h> int main(void) { int n0; scanf("%d",&n0); int a[1000]; for(int i=0; i<n0; i++){ scanf("%d",&a[i]); } for(int i=0; i<n0; i++){ int n; n=a[i];//i==0shi int cont=0; while(n!=1){ if(n%2==0&&n>0){ n=n/2; cont++; } else if(n%2!=0 && n>0){ n=(3*n+1)/2; cont++; } for(int j=0; j<n0; j++){ if(i==j && a[i]==a[j]){ continue; } if(a[j]==n){ a[j]=1; } } // for(int k=i+1;k<n0;k++){ // if(a[k]==n){ // a[k]=160; // } } } int max=0; for(int i=1; i<n0; i++){ if(a[i]>a[max]){ int temp; temp=a[i]; a[i]=a[max]; a[max]=temp; } } int cont=0; int b[1000]; for(int i=0,k=0; i<n0; i++){ if(a[i]>1){ b[k]=a[i]; k++; cont++; } } for(int k=0; k<cont-1; k++){ printf("%d ",b[k]); } printf("%d",b[cont-1]); return 0; } ```![Insert picture description here](https://img-blog.csdnimg.cn/3c9965ed820c4fa999e8c5366689f323.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAaGFsb3V3b3NoaXdvbXk=,size_16,color_FFFFFF,t_70,g_se,x_16#pic_center) Then there is the wrong point. I don't know what it is at present? Here is the correct answer ```c #include<stdio.h> int main() { int ask[101]={0}; int K; scanf("%d",&K); for(int i=0;i<K;i++) { int n; scanf("%d",&n); ask[n]=1; } //If a number is to be verified, the element subscript to it is set to 1 for(int i=1;i<101;i++) { if(ask[i]) // Operate only on the number of to be verified { int j=i; while(j>1) { if(j%2) j=(3*j+1)/2; else j=j/2; if(j<101&&ask[j]) { ask[j]=0; //Key numbers are numbers that cannot be overwritten by other numbers to be verified K--; //Just eliminate the number that can be covered by other numbers, and the rest is the key number if(j<i) break; //Therefore, the operation process is to eliminate the numbers that can be covered by other numbers } //The number less than i has been checked in the previous operation, so you can directly jump out to the next cycle } } } for(int i=100;i>0;i--) { if(ask[i]) { printf("%d%c",i,--K?' ':'\0');} //--K?' ':'-k?' ':'\ 0 ', k is the number to be verified. This statement can make the last number print out without outputting spaces } return 0; }

Study it tomorrow!