Group C of the seventh Blue Bridge Cup C language-(self-understanding questions)

Source: Internet
Author: User

Group C of the seventh Blue Bridge Cup C language-(self-understanding questions)
Group C of the seventh Blue Bridge Cup C language-(self-understanding questions)

It indicates that I have just checked my score. I have won the first prize in the provincial competition and will be eligible to go to Beijing. Then I will write a summary,
First, let's write down what I understand. After all, I am also a cainiao. I heard that the national competition is more difficult than the preliminaries...

Question 1
Newspaper pages

The daily report of Planet X is the same as that of the city Morning Post on Earth,
These are all individually stacked sheets. Each sheet is printed with four editions.

For example, a newspaper contains four pages: 5, 6, 11, 12,
It should be the top 2nd newspapers.

We found a newspaper on Planet X in space. The four pages are:
1125,1126, 1727,1728

Please calculate the total number of pages of the newspaper (that is, the maximum page number, not how many sheets of paper are used )?
Enter a number indicating the total number of pages.
Note: You must submit an integer and do not enter any additional content or descriptive text.
I didn't fill in this question. To tell the truth, I didn't understand it. I didn't read the paper.
No ..
Post it...

1125 + 1126 + 1727 + 1728 = 1 + 2 + X, X equals 5703,5703 equals 2851 + 2852

Question 2
Number of coal balls

There is a pile of coal balls in a triangular pyramid shape. Details:
Put 1 in the first layer,
Layer 2 3 (arranged as triangles ),
Layer 3 6 (arranged as triangles ),
Layer 10 (arranged as triangles ),
....
If there are a total of 100 floors, how many coal balls are there?

Enter a number indicating the total number of coal balls.
Note: You must submit an integer and do not enter any additional content or descriptive text.

#include
  
   #include
   
    using namespace std;int getInt(int n) {    int n1 = 1;    int sum = n1;    for (int i = 2; i <= n; i++) {        sum = i + n1;        n1 = sum;    }    return sum;}int main() {    int sum = 0;    for (int i = 1; i <= 100; i++) {        sum += getInt(i);    }    cout << sum << endl;    return 0;}
   
  

I entered 5050 at the time and calculated the layer 100th .. The question requires a total of 100 layers.
Answer171700

Question 3
Square Strange Circle

If every digit of a positive integer is squared and then summed, a new positive integer is obtained.
Perform the same processing on the new positive integers.

In this way, you will find that no matter what number you start to take,
If it does not fall into 1, it will fall into the same cycle.

Write the largest number in the cycle.
Enter the maximum number.
Note: You must submit an integer and do not enter any additional content or descriptive text.

#include
  
   #include
   
    #include
    
     using namespace std;char s[100];int getInt(char *s) {    int sum = 0;    int len = strlen(s);    for (int i = 0; i < len; i++) {        sum += (s[i]-'0')*(s[i]-'0');    }    return sum;}int main() {    int num = 3;    int MAX = 0;    for (int i = 0; i < 100; i++) {        sprintf(s, "%d", num);        num = getInt(s);        MAX = max(MAX, num);    }    cout << MAX << endl;    return 0;}
    
   
  

Answer145Some of them are 1 and can be printed out.

Question 4
Print Square
11 points
Xiaoming wants to output m x n squares on the console.
For example, the output of 10x4 is as follows:
+-+
|
+-+
|
+-+
|
+-+
|
+-+

(If questions are displayed, see Figure 1.jpg ])

The following is a program written by James. Analyze the process and fill in the code that is missing in the dash section.

# Include
  
   
// Print the m column. The void f (int m, int n) {int row; int col; for (row = 0; row
   
  

Note: Fill in only the content that is missing in the dashes. Do not add any existing content or descriptive text.
For loop. I wrote it like this.

for(col=0; col 

Question 5
13 points
Quick sorting

Sorting is often used in various scenarios.
Quick sorting is a very common and efficient algorithm.

The idea is: first select a "ruler ",
Use it to screen the entire queue,
To ensure that the element on the left is not greater than it, and the element on the right is not smaller than it.

In this way, the Sorting Problem is divided into two subintervals.
Sort the subintervals separately.

The following code is an implementation. Analyze and enter the code that is missing in the dash section.

#include  void swap(int a[], int i, int j){int t = a[i];a[i] = a[j];a[j] = t;}int partition(int a[], int p, int r){int i = p;int j = r + 1;int x = a[p];while(1){while(i  x);if(i>=j) break;swap(a,i,j);}______________________;return j;}void quicksort(int a[], int p, int r){if(p   

The answer is:Swap (a, p, j)

Question 6
6.
15 points
Pooled Formula

B DEF
A + — + ——- = 10
C GHI

(If questions are displayed, see Figure 1.jpg ])

In this formula, ~ I Represents 1 ~ 9. Different letters indicate different numbers.

For example:
6 + 8/3 + 952/714 is a solution,
5 + 3/1 + 972/486 is another solution.

How many solutions does this formula have?

Note: Your submission should be an integer. Do not enter any additional content or descriptive text.


Remember not to use fabs (...) <1E10 equals
Dfs ideas

#include  #include  #includeusing namespace std;int a1[9], book[9], COUNT = 0;bool getSum(int *a) { int A = a[0], B = a[1], C = a[2]; int DEF = a[3]*100+a[4]*10+a[5], GHI = a[6]*100+a[7]*10+a[8]; if ((B*GHI+DEF*C)%(C*GHI) != 0) return false; if (A+(B*GHI+DEF*C)/(C*GHI) == 10) return true; return false; }void dfs(int step) { if (step == 9) { if (getSum(a1)) COUNT++; return; } for (int i = 0; i < 9; i++) { if (book[i] == 0) { book[i] = 1; a1[step] = i+1; dfs(step+1); book[i] = 0; } }}int main() { dfs(0); cout << COUNT << endl; return 0;}  

Answer29

Question 7
19 points
Winter vacation homework
At present, primary school mathematics is not so interesting.
Take a look at this winter vacation assignment:
□+ □= □
□- □= □
□×□= □
□Items □= □
(If the screenshot is displayed, see Figure 1.jpg ])
Each square represents 1 ~ A number in column 13, but cannot be repeated.
For example:
6 + 7 = 13
9-8 = 1
3*4 = 12
10/2 = 5
And:
7 + 6 = 13
9-8 = 1
3*4 = 12
10/2 = 5
Two solutions are supported. (Different solutions are calculated after addition and multiplication exchange law)

How many solutions have you found?
Or dfs ideas

#include  #include  #includeusing namespace std;int a1[13], book[13], COUNT = 0;bool getSum(int *a) { if (a[9]%a[10] != 0) return false; return ( a[0]+a[1] == a[2] && a[3]-a[4] == a[5] && a[6]*a[7] == a[8] && a[9]/a[10] == a[11] );}void dfs(int step) { if (step == 13) { if (getSum(a1)) COUNT++; return; } for (int i = 0; i < 13; i++) { if (book[i] == 0) { book[i] = 1; a1[step] = i+1; dfs(step+1); book[i] = 0; } }}int main() { dfs(0); cout << COUNT << endl; return 0;}  

It took about 5 minutes to run ..
Answer64
If you have a good solution, please let me know that my level is limited. Hey

Question 8
21 points
Hail count

Any given positive integer N,
If it is an even number, run N/2.
If it is an odd number, run N * 3 + 1.

Generate new numbers and perform the same action.
We can see that this number will rise to a very high value in a moment,
After a while, I landed again.
In this way, it will eventually fall to "1"
This is a bit like the growth of small hail particles in the Hail Clouds.

For example, N = 9

As you can see, when N = 9, the "small Hail" was at the height of 52.

Input Format:
A positive integer N (N <1000000)
Output Format:
A positive integer that represents a number not greater than N. the maximum number of hits during the hail number transformation.

For example, enter:
10
The program should output:
52

For example, enter:
100
The program should output:
9232

I believe that many children's shoes have been pitted by this question... Hahaha. Check the meaning of the question.
A positive integer indicating a number not greater than N
Well, I pushed it to the front. In the test room, I wrote the code in less than five minutes... And then kneel down ..
Error Code

#include  #include  using namespace std;int getInt(int N) { if (N%2 == 0) return N/2; return N*3+1;}int main() { int N; scanf("%d", &N); int MAX = N; while(N != 1) { N = getInt(N); MAX = max(MAX, N); } cout << MAX << endl; return 0;}  

After I finish writing, I feel so cool...
After testing the data, I felt that something was wrong. Was it because the test data was wrong ..
In fact, I understood the question wrong.
Correct code

#include  #include  using namespace std;int getInt(int N) { if (N%2 == 0) return N/2; return N*3+1;}int main() { int N, MAX, M; scanf("%d", &N); MAX = N; for (int i = N; i >= 1; i--) { M = i; while(M != 1) { M = getInt(M); MAX = max(MAX, M); } } cout << MAX << endl; return 0;}  

If the number of inputs is greater than 122222, it will time out ..
Water some data.

Question 9
25

Card placement

Have you ever played HuaRong road games?
This is a similar but simpler game.
Look at the 3x2 lattice below

+—+—+—+
| A | * | * |
+—+—+—+
| B | | * |
+—+—+—+

Five cards are displayed, with A representing Guan Yu, B Representing Zhang Fei, and * representing soldiers.
Another lattice is empty.

You can move a card to an adjacent space (the diagonal corner is not adjacent ).
The goal of the game is to switch positions between Guan Yu and Zhang Fei. Other cards can be used wherever they are.

Input Format:
Enter two lines and six characters to indicate the current situation.

Output Format:
An integer that represents the minimum number of steps before you can change AB (other card positions are random)

Resource conventions:
Peak memory consumption <256 M
CPU consumption <1000 ms

Memory-based search
No ..

10th
Password disconnection

Archaeologists on Planet X discovered a group of ancient passwords left behind.
These passwords are sequences of seeds from four plants, namely, A, B, C, and D.
After careful analysis, we found that these password strings should have been symmetric (that is, the image strings we mentioned ).
Because of its long history, many of the seeds fall off, the image features may be lost.

Your task is:
Given a currently seen password string, calculate the number of seeds that need to be dropped from the original state to the current state.

Enter a line to indicate the current password string (length not greater than 1000)
A positive integer is required to indicate the number of seeds that have fallen off at least.

For example, enter:
ABCBA
The program should output:
0

For example, enter:
ABECDCBABC
The program should output:
3

Resource conventions:
Peak memory consumption <256 M
CPU consumption <3000 ms

Please output the output strictly as required. Do not print it in a way similar to: "Please input ..." .
All codes are stored in the same source file. After debugging is successful, copy and submit the source code.
Note: The main function must return 0.
Note: Only ansi c/ansi c ++ standards are used. Do not call special functions that depend on the compiling environment or operating system.
Note: All dependent functions must be explicitly included in the source file # include. Common header files cannot be omitted through engineering settings.

When submitting, select the expected compiler type.
Hear from the gods about Dynamic Planning
No...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.