Crystal's [starch cup ยท blue bridge on cloud - algorithm training camp] week 1 assignment

First week of Blue Bridge Cup preparation

Question 1: running training

Problem description
Xiao Ming wants to do a running training. At the beginning, Xiao Ming is full of physical strength, and the physical strength value is 10000.

If Xiao Ming runs, he will lose 600 physical strength per minute.
If Xiao Ming has a rest, he will increase his physical strength by 300 per minute.
The loss and increase of physical strength vary evenly.

Xiao Ming plans to run for one minute, rest for one minute, run for another minute, rest for another minute... This cycle.
If Xiaoming's physical strength reaches 0 at a certain time, he will stop exercising. How long will Xiaoming stop exercising.
In order to make the answer an integer, please output the answer in seconds. Only the number, not the unit, is filled in the answer.

Answer submission
This is a result filling question. You just need to calculate the result and submit it.
The result of this question is an integer. When submitting the answer, only fill in this integer. If you fill in the redundant content, you will not be able to score.

#include<iostream>
using namespace std;
//Question 1, running training

int main()
{
	int total = 10000;
	int i = 0, j = 0,sum = 0;//i is used to record the time of running and j is used to record the time of rest
	while (total > 0)
	{
		
		if(total >600)
		{
			i += 60;
			total -= 600;
			total += 300;
			j += 60; 
		}
		else
		{
			i += total /10;
			total = 0;
			break;
		}
		
	}
	sum = i + j;//Total seconds of sum storage
	cout << "Xiao Ming is here" << sum << "Stop training in seconds" << endl;
	system("pause");
}

The operation results are as follows:

Question 2: factorial divisor

Problem description
Define factorial n= one × two × three × ··· × n.
Excuse me 100! (factorial of 100) how many divisors are there.
Answer submission
This is a question to fill in the blanks. You just need to calculate the results and submit them.
The result of this question is an integer. When submitting the answer, only fill in this integer. If you fill in the redundant content, you will not be able to score.

Necessary mathematical knowledge:
If the positive integer n can be decomposed into p1a1*p1a2 *... pk^ak
Where pi is two different prime numbers and ai is the corresponding index, then the number of divisors of n is (1+a1)(1+a2)... (1+ak)
for example
180=22335=22*325
The number of divisors of 180 is (1 + 2) (1 + 2) * (1 + 1) = 18.

#include<iostream>
using namespace std;

int NUM = 100;
int a[101];//An array used to store prime divisors
void resolve(int num)//Find the prime divisor of each number from 1 to 100 and store it in the array
{
	int i = 2;//With 2, there will be no multiple of 2
	while (i <= num)
	{
		if (num % i == 0)
		{
			a[i]++;//Similar to bucket sorting, store the number of occurrences of these prime divisors
			num /= i;//Keep getting rid of the prime divisor until num becomes 1
			if (num == 1)
			{
				return;//Returns the for loop of the main function, and the i of the main function becomes 2, 3, 4, 5, 6.. To 100
			}
		
		}
		else
		{
			i++;//If it can't become 1, continue to divide by a larger prime divisor
		}
	}
}

int main()
{
	int i;
	for (i = 2; i <= NUM; i++)
	{
		resolve(i);

	}
	long long count = 1;//Initializes a large long integer used to store the final result
	for (int j = 2; j <= NUM; j++)
	{
		if (a[j])//If the corresponding number appears, multiply it
		{
			count *= a[j] + 1;
		}
		
	}
	cout << count << endl;
	system("pause");

}

Program execution results:

Question 3: stack order

Problem description
Planet X pays special attention to order. All roads are one-way streets.
A fleet of 16 beetles started successively according to the number, caught in other traffic flows and moved forward slowly.
There is a dead end on the roadside, which can only allow one car to pass. It is a temporary checkpoint, as shown in the figure.
Planet X is so rigid that every passing car is required to enter the checkpoint, or it may be released without inspection, or it may be carefully inspected.
If the order of vehicles entering and leaving the checkpoint can be staggered arbitrarily.
So, how many possible orders will the team take when it gets on the road again?
For convenience, it is assumed that the checkpoint can accommodate any number of cars.
Obviously, if the fleet has only one vehicle, there may be one order; 2 possible sequences of 2 vehicles; There are 5 possible sequences for 3 vehicles.
There are 16 cars now, pro! You need to calculate the number of possible orders.

Answer submission
This is an integer. Please submit the answer through the browser and do not fill in any redundant content (such as explanatory text).

#include<iostream>
using namespace std;

int f(int n, int m)//m is the number of vehicles in the station and n is the number of vehicles not entering the station
{

	if (n == 0)
	{
		return 1;//All the cars have entered the station
	}
	if (m == 0)
	{
		return f(n - 1, 1);
	}
	if (m > 0)
	{
		return f(n - 1, m + 1) + f(n, m - 1);
	}
}


int main()
{
	cout<<f(16,0);
	system("pause");
}

The operation results are as follows:

Question 4: Goldbach conjecture

[problem description]
Goldbach conjecture holds that even numbers not less than 4 can be expressed as the sum of two prime numbers.
You don't need to prove this theorem, but you can decompose a limited number of even numbers by computer to verify whether it is feasible.
In fact, there are many different decomposition schemes for an even number. We are concerned about the scheme containing a smaller prime number.
For a given numerical range, we want to know what is the largest prime in these schemes containing smaller prime numbers.
For example, within 100, the number is 19, which is contributed by the decomposition of 98.
What you need is within 10000. What's this number?
[answer submission]
This is a question to fill in the blanks. You just need to calculate the results and submit them. The result of this question is one
An integer. Only fill in this integer when submitting the answer. You can't score if you fill in the extra content.

Question 5: Book arrangement

[problem description]
10 books numbered 1 ~ 10 shall be placed on the bookshelf, and the books with adjacent numbers shall not be placed in adjacent positions.
Please calculate how many different permutations there are.
[answer submission]
This is a question to fill in the blanks. You just need to calculate the results and submit them. The result of this question is one
An integer. Only fill in this integer when submitting the answer. You can't score if you fill in the extra content.

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int ans = 0, a[] = { 1,2,3,4,5,6,7,8,9,10 };
	do {
		if (abs(a[0] - a[1]) == 1 || abs(a[1] - a[2]) == 1 || abs(a[2] - a[3]) == 1 || abs(a[3] - a[4]) == 1 || abs(a[4] - a[5]) == 1 || abs(a[5] - a[6]) == 1 || abs(a[6] - a[7]) == 1 || abs(a[7] - a[8]) == 1 || abs(a[8] - a[9]) == 1)
			continue;
		ans++;
	} while (next_permutation(a, a + 10));//next_permutation is a function of full permutation. Remember the form
	cout << ans << endl;
	return 0;
}

The operation results are as follows:

Question 6: monkeys divide bananas

[problem description]
The five monkeys were good friends and fell asleep on the coconut tree by the sea. During this period, a merchant ship forgot a lot of bananas and left on the beach.
The first monkey woke up and divided the bananas into five piles. When there was one left, he ate it and hid one of his bananas to continue sleeping.
The second monkey woke up and divided the bananas into five piles again. When there were two left, he ate them and hid one of them to continue to sleep.
The third monkey woke up and divided the bananas into five piles again. When there were three left, he ate them and hid one of them to continue to sleep.
The fourth monkey woke up and divided the bananas into five piles again. When there were four left, he ate them and hid one of them to continue sleeping.
The fifth monkey woke up and divided the bananas into five piles again. Ha ha, there's just no left!
Please calculate the minimum number of bananas at the beginning.
[answer submission]
This is a question to fill in the blanks. You just need to calculate the results and submit them. The result of this question is one
An integer. Only fill in this integer when submitting the answer. You can't score if you fill in the extra content.

Keywords: C++ Algorithm

Added by AndyB on Mon, 10 Jan 2022 07:27:11 +0200