The 7th Blue Bridge Cup Provincial Tournament javaB group-sub-group

Sub-group

Nine athletes participate in the competition and need to be divided into 3 groups for preliminaries.
What are the grouping schemes?

We mark athletes as A,B,C,...I
The following program lists all the grouping methods.

The normal output of the program is:
ABC DEF GHI
ABC DEG FHI
ABC DEH FGI
ABC DEI FGH
ABC DFG EHI
ABC DFH EGI
ABC DFI EGH
ABC DGH EFI
ABC DGI EFH
ABC DHI EFG
ABC EFG DHI
ABC EFH DGI
ABC EFI DGH
ABC EGH DFI
ABC EGI DFH
ABC EHI DFG
ABC FGH DEI
ABC FGI DEH
ABC FHI DEG
ABC GHI DEF
ABD CEF GHI
ABD CEG FHI
ABD CEH FGI
ABD CEI FGH
ABD CFG EHI
ABD CFH EGI
ABD CFI EGH
ABD CGH EFI
ABD CGI EFH
ABD CHI EFG
ABD EFG CHI
….. (Omitted below, 560 lines in total).

public class A
{
    public static String remain(int[] a)
    {
        String s = "";
        for(int i=0; i<a.length; i++){
            if(a[i] == 0) s += (char)(i+'A');
        }   
        return s;
    }

    public static void f(String s, int[] a)
    {
        for(int i=0; i<a.length; i++){
            if(a[i]==1) continue;
            a[i] = 1;
            for(int j=i+1; j<a.length; j++){
                if(a[j]==1) continue;
                a[j]=1;
                for(int k=j+1; k<a.length; k++){
                    if(a[k]==1) continue;
                    a[k]=1;
                    System.out.println(_);  //Fill in the blank position
                    a[k]=0;
                }
                a[j]=0;
            }
            a[i] = 0;
        }
    }

    public static void main(String[] args)
    {
        int[] a = new int[9];       
        a[0] = 1;

        for(int b=1; b<a.length; b++){
            a[b] = 1;
            for(int c=b+1; c<a.length; c++){
                a[c] = 1;
                String s = "A" + (char)(b+'A') + (char)(c+'A');
                f(s,a);
                a[c] = 0;
            }
            a[b] = 0;
        }
    }
}

Read the code carefully and fill in the missing content in the underlined part.

Note: Do not fill in any existing content or explanatory text.

This problem does not need to spend too much time to look at the code. It may not be worthwhile to look at the code at this time. You need to find some problem-solving skills. First of all, look at the string s output by this loop

package com.lanqiao.seven.Test;

public class Demo04 {

    public static String remain(int[] a)
    {
        String s = "";
        for(int i=0; i<a.length; i++){
            if(a[i] == 0) s += (char)(i+'A');
        }   
        return s;
    }

    public static void f(String s, int[] a)
    {
        for(int i=0; i<a.length; i++){
            if(a[i]==1) continue;
            a[i] = 1;
            for(int j=i+1; j<a.length; j++){
                if(a[j]==1) continue;
                a[j]=1;
                for(int k=j+1; k<a.length; k++){
                    if(a[k]==1) continue;
                    a[k]=1;
                    System.out.println(s);  //Fill in the blank position
                    a[k]=0;
                }
                a[j]=0;
            }
            a[i] = 0;
        }
    }

    public static void main(String[] args)
    {
        int[] a = new int[9];       
        a[0] = 1;

        for(int b=1; b<a.length; b++){
            a[b] = 1;
            for(int c=b+1; c<a.length; c++){
                a[c] = 1;
                String s = "A" + (char)(b+'A') + (char)(c+'A');
                f(s,a);
                a[c] = 0;
            }
            a[b] = 0;
        }
    }
}

The output result is as follows:
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
………………

Through this we can see that it is the number in the first column, then we can see that a method (remain) is not used anywhere in the program, and we can also see what it outputs

package com.lanqiao.seven.Test;

public class Demo04 {

    public static String remain(int[] a)
    {
        String s = "";
        for(int i=0; i<a.length; i++){
            if(a[i] == 0) s += (char)(i+'A');
        }   
        return s;
    }

    public static void f(String s, int[] a)
    {
        for(int i=0; i<a.length; i++){
            if(a[i]==1) continue;
            a[i] = 1;
            for(int j=i+1; j<a.length; j++){
                if(a[j]==1) continue;
                a[j]=1;
                for(int k=j+1; k<a.length; k++){
                    if(a[k]==1) continue;
                    a[k]=1;
                    System.out.println(remain(a));  //Fill in the blank position
                    a[k]=0;
                }
                a[j]=0;
            }
            a[i] = 0;
        }
    }

    public static void main(String[] args)
    {
        int[] a = new int[9];       
        a[0] = 1;

        for(int b=1; b<a.length; b++){
            a[b] = 1;
            for(int c=b+1; c<a.length; c++){
                a[c] = 1;
                String s = "A" + (char)(b+'A') + (char)(c+'A');
                f(s,a);
                a[c] = 0;
            }
            a[b] = 0;
        }
    }
}

The output result is as follows:
GHI
FHI
FGI
FGH
EHI
EGI
EGH
EFI
EFH
EFG
DHI
DGI
DGH
DFI
DFH
DFG
DEI
DEH
DEG
DEF
GHI
……………………
It can be seen from the output result that this is the result of the third column, then what is missing is the result of the second column, then we need to think about it, the letter in the second column is the remaining after removing the first and third Then, we can borrow the formula (it appears more frequently), namely: s += (char)(i+'A'), but we need to modify it (according to the idea of ​​the questioner, it should be the outer circle Start spelling, all the way to the inner circle), the corresponding code is as follows:

package com.lanqiao.seven.Test;

public class Demo04 {

    public static String remain(int[] a)
    {
        String s = "";
        for(int i=0; i<a.length; i++){
            if(a[i] == 0) s += (char)(i+'A');
        }   
        return s;
    }

    public static void f(String s, int[] a)
    {
        for(int i=0; i<a.length; i++){
            if(a[i]==1) continue;
            a[i] = 1;
            for(int j=i+1; j<a.length; j++){
                if(a[j]==1) continue;
                a[j]=1;
                for(int k=j+1; k<a.length; k++){
                    if(a[k]==1) continue;
                    a[k]=1;
                    System.out.println(""+(char)(i+'A')+(char)(j+'A')+(char)(k+'A'));  //Fill in the blank position
                    a[k]=0;
                }
                a[j]=0;
            }
            a[i] = 0;
        }
    }

    public static void main(String[] args)
    {
        int[] a = new int[9];       
        a[0] = 1;

        for(int b=1; b<a.length; b++){
            a[b] = 1;
            for(int c=b+1; c<a.length; c++){
                a[c] = 1;
                String s = "A" + (char)(b+'A') + (char)(c+'A');
                f(s,a);
                a[c] = 0;
            }
            a[b] = 0;
        }
    }
}

The output result is as follows:
DEF
DEG
DEH
DEI
DFG
DFH
DFI
DGH
DGI
DHI
EFG
EFH
…………………………

Then it's the number in the second column, then combining the above inference, we can get the following code:

package com.lanqiao.seven.Test;

public class Demo04 {

    public static String remain(int[] a)
    {
        String s = "";
        for(int i=0; i<a.length; i++){
            if(a[i] == 0) s += (char)(i+'A');
        }   
        return s;
    }

    public static void f(String s, int[] a)
    {
        for(int i=0; i<a.length; i++){
            if(a[i]==1) continue;
            a[i] = 1;
            for(int j=i+1; j<a.length; j++){
                if(a[j]==1) continue;
                a[j]=1;
                for(int k=j+1; k<a.length; k++){
                    if(a[k]==1) continue;
                    a[k]=1;
                    System.out.println(s+" "+(char)(i+'A')+(char)(j+'A')+(char)(k+'A')+" "+remain(a));  //Fill in the blank position
                    a[k]=0;
                }
                a[j]=0;
            }
            a[i] = 0;
        }
    }

    public static void main(String[] args)
    {
        int[] a = new int[9];       
        a[0] = 1;

        for(int b=1; b<a.length; b++){
            a[b] = 1;
            for(int c=b+1; c<a.length; c++){
                a[c] = 1;
                String s = "A" + (char)(b+'A') + (char)(c+'A');
                f(s,a);
                a[c] = 0;
            }
            a[b] = 0;
        }
    }
}

The result is: s+" "+(char)(i+’A’)+(char)(j+’A’)+(char)(k+’A’)+" "+remain(a)

Intelligent Recommendation

The 4th Blue Bridge Cup Javab Group Provincial Tournament - Revitalizing China

The 4th Blue Bridge Cup Javab Group Provincial Tournament - Revitalizing China Topic description Xiaoming participated in the fun gain of the school, one of which is: jumping. Painted some plaids on t...

2020 Eleventh Blue Bridge Cup Javab Group Provincial Tournament

The first question is 1 to 2020 has a few '2' Direct traversal answer: 624 Question 2 find 2020 Direct traversal I am manual copying of the array to measure the array is 300 * 300, and then programmat...

2020, Blue Bridge Cup Provincial Tournament Javab Group Looking for 2020

Simple simulation To the right, down, to the right...

The 11th Blue Bridge Cup Provincial Tournament Javab Group - Looking for 2020

【Problem Description】 Small blue has a digital matrix, which contains only numbers 0 and 2. Xiao Lan likes 2020, he wants to find How many 2020 is present in this digital matrix. Small blue only follo...

Blue Bridge Cup 2013 Provincial Tournament [Fourth] -JAVAB Group Analysis

Refer to the snippet and official code given by the official website of the Blue Bridge. Blue Bridge Cup official explaining video:https://www.lanqiao.cn/courses/2737 Time: 4 hours A. Week at the end ...

More Recommendation

The 7th Group B Provincial Tournament of the Blue Bridge Cup-Cut the stamps

As shown in [Picture 1.jpg], there are 12 stamps with 12 zodiac signs connected together. Now you have to cut out 5 sheets from it. The requirement must be connected. (Just connecting a corner is not ...

Blue Bridge Cup 7th Provincial Tournament Group B - four square and

Four square and theorem, also known as the Lagrangian theorem: Each positive integer can be represented as a square sum of up to 4 positive integers. If 0 is included, it may be represented as a squar...

Blue Bridge Cup 7th Javab Group

(8) Title: Four square and...

2018 Provincial Blue Bridge Cup JavaB Group

First question: the first few days solution: Second question: check the grid As shown in Figure p1.png, there are countless small 1x1 squares on the 2D plane. We draw a circle with a radius of 1000 ce...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top