Chapter 230 There are mountains beyond the mountains
The first programming practice question I answered was of average difficulty. It was a basic question that I had an idea of right after reading it and there were not many points where I got stuck.
Test your basic skills and proficiency.
Li Yan had just finished reading the questions and was about to start when she saw another prompt on the big screen:
"The second place to complete the first stage of the test: B-7, New Taipei Middle School, Deng Yudi, took 29:28"
The moment he was distracted, there was a third one:
"Third place in the first stage: A-11, Xin'an Middle School, Zheng Da, time 29:30"
Li Yan knew who this person was. He was a potential stock that Xin'an Middle School should really value. In his first year of high school, he took second place in the league's high school improvement group, and the first place was Deng Yudi.
Li Yan smiled and nodded slightly, feeling that she had not made a mistake in choosing the right person, but she also felt a little more urgent.
That’s good, it gives us a competitive feel.
Being invincible is indeed lonely, so he needs a bigger stage, even if it means some setbacks and blows.
The screen only shows the data of the first three completed stages. Judging from the display ratio, the first three completed records of the three stages should be displayed on top at the same time... If you are the first to complete all three stages, you can really make a strong presence.
Li Yan didn't want to be distracted, and indeed he wasn't distracted. He just glanced at it, and his mind was busy analyzing a bunch of things.
The hand movements do not stop, and the basic idea of the question is just like that. If you compare the speed, it still tests your proficiency in writing code.
Soon the problem was solved. Li Yan confidently clicked submit and saw the next question:
素数,是仅有其本身和数字1两个约数的数,例如1、3、5、7、17、101和10007……
Li Yan seemed to see the confident expression of the teacher who set the questions for a moment. From this beginning, it seemed that the difficulty of the questions would be raised to a higher level.
"Input a set of words, each word is composed of letters a-z. Each letter corresponds to a specific value, letter a corresponds to 1, b corresponds to 2, and so on.
If the sum of the letters of a word is a prime number, then the word is a prime word (prime world). Please write a program to determine whether a word is a prime word.
If the sum of the letters of a word is a prime number, then output “It is a prime word”; otherwise, output “It is not a prime word”.
Li Yan actually had an idea right away. The length of a word is limited, and the corresponding numbers are limited. So we can calculate an upper limit, and then select the prime numbers in the range to make a set u. Then we can directly use the formula to calculate the numbers and x corresponding to the letters of the word, and compare the results directly with the prime number set. If the result is u[x]=1, then we output It is a prime word, and vice versa. The problem is solved.
In Li Yan's opinion, the calculation with formulas at the end is not the real difficulty of this question; the real test is the prime number screening.
You know, the English name for "pneumoconiosis caused by inhalation of silicate fines or quartzite ash" is pneumonoultramicyoscpicailicovolcanoconiosis, which has a full 45 letters.
This is not necessarily the longest, but the longest word that Li Yan knows. Even if we take the average value of 13, and take a word with 50 letters, the upper limit will be 650.
This prime number is not easy to sift...
No, that’s not the problem. If we don’t know the upper limit, what if there are words in the world consisting of 1913 letters?
Who knows what will come out of some professional terms, so does this prime number screening have to be calculated up to 20,000?
This difficulty is no joke.
In an instant, Li Yan realized that something was wrong. This was not the most difficult two-person cooperation problem. Even an almighty god of war like him was hesitant about this problem, so what about others playing snake games?
He pushed the mouse wheel as if possessed by a ghost:
"Given a set of words, the letters of the words are randomly composed, each word is in one line, and the number of letters does not exceed 20"
Damn it... He almost dug his hands into the keyboard for a moment. It looked like the questions were all finished, but why was this line hidden?
No more than 20, randomly given, that is, the upper limit does not exceed 520, you only need to screen prime numbers between 1 and 520.
How to sift? Hard sift.
Li Yan had memorized the set of prime numbers from 1 to 300, and after excluding some obvious composite numbers, there were not many numbers left to calculate.
Damn it, if I had known I would have counted to 1000, wouldn’t I be killing people right now?
A question that was not too difficult actually made Li Yan feel nervous. As soon as he finished the prime number screening set, he started to construct the formula without stopping.
In the end, he didn't even check it and just clicked submit the moment he finished writing the program.
Ding Dong!
"The first person to complete the second stage of the questions: B-7, New Taipei High School, Deng Yudi, took 34:41" "The second person to complete the second stage of the questions: E-12, New Taipei First High School, Li Yan, took 36:54"
What the hell? The whole place was agitated. Some people had just started the second stage, but two of them had already finished the second stage?
Isn't this Xinbei No. 1 High School a junior high school? Why are junior high school students pretending... Then they saw clearly that the name was Li Yan, was it serious?
The young woman next to Director Jin, Vice Chairman Zhang of the Linjiang Provincial Computer Association, was a little surprised. "A four-and-a-half-hour exam, and two stages only took one hour? Isn't that a bit too much?"
"It's beyond expectations, isn't that good?" Director Jin said with a smile.
But he was actually not sure in his heart. If Li Yan was just trying to attract attention in the end, he would lose face.
Li Yan in the audience was a little shocked. Deng Yudi started the second stage of questions slower than him. Even if he didn't read all the questions at the beginning and wasted some time, Deng Yudi at least spent basically the same amount of time as him to solve the second stage.
Li Yan is very confident that his hand speed is better than Deng Yudi's, so Li Yan should be faster on basic questions.
So how did Deng Yudi manage to be faster than Li Yan, who had memorized prime numbers between 1 and 300, in the second question?
There are two possibilities. One is that Deng Yudi memorized the prime numbers between 1 and 520. The other is that this guy directly wrote a program to screen prime numbers - and it is very efficient.
No matter which possibility it is, this guy is indeed a tough guy...
But now it's time to focus on the third stage, which is the cooperation question. This question will undoubtedly be the most difficult today - or the one with the most workload. However, Chen Fan hasn't figured it out yet, so Li Yan can only figure it out on his own for the time being:
"Given several line segments of a straight line, the straight line is the X-axis, and the coordinates of the line segments are [Li, Ri]. Find the minimum number of line segments required to cover the interval [0, m]."
Li Yan frowned slightly, this question didn't seem right.
"The first line of input gives the number of test cases, followed by a blank line.
Each test case first gives an integer M (M is less than or equal to 5000 and greater than or equal to 1), followed by several lines, each line represents a line segment with 'Li Ri'..."
"Output: For each test case, the first line of the output is a number, indicating the minimum number of line segments covering the interval [0, m]. The next few lines represent the selected line segments, giving the coordinates of the line segments, sorted by the left end. If there is no solution, that is, [0, m] cannot be covered by the given line segments, then the output is 0..."
It is indeed difficult. Li Yan did not start working on the question immediately after reading it. If a bug is found hastily in this type of question, the time cost of fixing the program will be higher.
You must first have a sufficiently complete and feasible idea.
The big screen also has the third finisher of the second phase:
"Third place to complete the second stage: E-11, New Taipei First High School, Chen Fan, time 45:02"
45 points? He was not just a few minutes late. It seemed that Chen Fan spent quite a lot of time answering the written test questions.
But then again, “speed” was not the main requirement for this exam.
"Li Yan?" Chen Fan's voice came from the headset.
"receive."
"Why are you so fast? That Deng Yudi is crazy, one by one, so fast, there is no need!"
Indeed, although the last question is difficult, three hours is definitely enough. The first thing to do is to ensure the accuracy and then improve the brilliance of your ideas.
Li Yan just wants to show off, but she doesn't know what's going on with this Deng Yudi.
"Aren't you pretty fast? You made it into the top three in the second stage." Li Yan was indeed surprised. Chen Fan has never relied on speed as an advantage, but he was able to get a showcase spot in a high school home court full of strong players.
"Oh, I memorized the prime numbers between 0 and 600, which saved me a lot of effort on the last question."
you?
For now, please don’t complain and just read the questions.
"It's better to become famous early, Chen Fan."
(End of this chapter)