OJ Question Record: Question A: Answers are rewarded

Question A: Answers are rewarded

Topic requirements: A
certain program group planned a prize-answering activity.
The rules of the activity are as follows:
contestants need to answer 10 questions (1-10). The difficulty gradually rises. Once the player answers the current question correctly, the player’s score doubles. When the player answers the wrong question, the score corresponding to the current question number will be deducted (the player must answer the question, and if the player does not answer, the error will be handled). Then it will be directly counted as 0 points and will be disqualified. Each player has a starting point of 10 points, with a minimum score of 0.
Now give a score upper limit n, please find out the scores within this upper score limit (interval [0, n]) that cannot appear when completing all ten questions, and give it.
Input
Input n (n<=100) in the first line to indicate the upper limit of the score.
Output
All the numbers that are not satisfied in the interval [0,n] are output in ascending order, and each output occupies one line.
Sample input Copy
4
Sample output Copy
3

Problem-solving idea:
recursively load all score results into the set container. Then start traversing from 0 (to the end of n), and search in the container at the same time. If the corresponding score is not found, it will be output.

Important note:
At the beginning, I did not understand the meaning of the question, thinking that the score required by the question was the score in the process of doing the question (misled by the phrase "disqualified to do the question" in the question). Put this score into the container, but the question requires the total score after completing 10 questions, so my approach led to the wrong result.

Customs clearance code:

#include <iostream>
#include <set>

using namespace std;

set<int> ass;

void fun(int score, int num) {
    
    
	if (num > 10) {
    
    
		ass.insert(score);
		return ;
	}
	
	fun(score * 2, num + 1);
	fun(score - num, num + 1);
} 

int main() {
    
    
	int n;
	
	cin >> n;

	fun(10, 1);
	
	for (int i = 0; i <= n; i++) {
    
    
		if (ass.find(i) == ass.end()) {
    
    
			cout << i << endl;
		}
	}
	
	return 0;
} 

Customs clearance screenshot:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45711556/article/details/108189932