Nuggets team number online, help you Offer impromptu! Click for details

1. Title Description

The Callatz conjecture is described in 1001. In this case it’s a little bit more complicated. When we verify the Karazi conjecture, to avoid double counting, we can record every number encountered in the recursion. For example, when verifying n=3, we need to calculate 3, 5, 8, 4, 2, and 1. Then, when verifying n=5, 8, 4, and 2, we can directly determine the authenticity of Karaz’s conjecture without repeated calculation, because these four numbers have already been encountered in verifying 3. We call 5, 8, 4, 2 “covered” by 3. We call a number n in a sequence a “critical number” if n cannot be overridden by other numbers in the sequence.

Now, given a list of numbers to verify, we only need to verify a few of the key numbers so that we don’t have to double-check the rest. 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 contains a positive integer K (<100), and the second line contains K different positive integer n (1<n≤100) values to be verified, separated by Spaces.

Output format: The output of each test case is in one line, and the key numbers are output in descending order. Digits are separated by one space, but there is no space after the last digit in a line.

Example Value: 6 3 5 6 7 8 11 Example value: 7 6

Second, train of thought analysis

If a number is covered, a[n] will be greater than 1. If a[n] is covered, a[n] will be greater than 1.

AC code

Method one:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[10000] = {0};
    int k,n;
    cin>>k;
    for(int i=0; i<k; i++) { cin>>n;while(n! =1)// Start the Karazi conjecture
        {
            a[n]++;
            if(n%2= =0)
                n=n/2, a[n]++;
            else
                n=(3*n+1) /2, a[n]++;
        }
    }
    
    int temp;
    for(int i=100; i>=0; i--)// Print the largest number
    {
        if(a[i]==1)
        {
            temp=i;
            cout<<i;
            break; }}for(int i=100; i>=0; i--)// Print the remaining numbers from large to small, with Spaces in between
        if(a[i]==1&&i! =temp) cout<<""<<i;
    return 0;
}
Copy the code

Method 2:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[10000] = {0};
    int k,n;
    cin>>k;
    for(int i=0; i<k; i++) { cin>>n;while(n! =1)// Start the Karazi conjecture
        {
            a[n]++;
            if(n%2= =0)
                n=n/2, a[n]++;
            else
                n=(3*n+1) /2, a[n]++;
        }
    }
    int cnt=0;
    for(int i=100; i>=0; i--) {if(a[i]==1)
        {
            cnt++;
            if(cnt! =1)// Determine whether to add Spaces before output
		cout<<""; cout<<i; }}}Copy the code

Four,

Make persistent efforts, strive to brush a day product is insufficient, age into more than 😊