Noip2004 Problem Solving report

Source: Internet
Author: User

Question 1:
Jinjin's pocket money has always been managed by itself. At the beginning of each month, my mother gave Jin 300 yuan. Jin will budget the expenses for this month and will always make the actual expenses the same as the budget.

In order for Jin to learn how to save, her mother suggested that Jin could store the whole hundred yuan at any time. By the end of the year, she would add 20% yuan to Jin. Therefore, Jin has developed a savings plan: at the beginning of each month, if she expects more than 100 yuan or exactly 100 yuan at the end of the month after receiving the pocket money from her mother, she will save the whole hundred dollars to her mother and keep the remaining money in her own hands.

For example, Jin had 83 yuan in his hand in early November, and his mother gave Jin 300 yuan. Jin's estimated spending in November is 180 yuan, so she will save 200 yuan for her mother and leave 183 yuan for herself. By the end of June November, jinjin had three yuan left.

Jin found that the main risk of this savings plan was that money from his mother could not be taken out before the end of the year. It is possible that at the beginning of a month, the money in jinjin's hand plus the money given by her mother this month is not enough for the original budget of this month. In this case, jinjin will have to save money this month and compress the budget.

Now, based on your monthly budget for June January to December 2004, you can determine whether this situation will happen. If not, calculate how much money jinjin will have after her mother adds 2004 of the money she has stored in jinjin to jinjin by the end of 20%.

Problem solving process:
Deliver the score, simulate it, but pay attention to the remaining money in the final settlement. Do not forget to add the money that has not been spent for 12 months;
AC once every 15 minutes;
 

Question 2:
The cost of combining N fruit and weight is the sum of weight and the sum of weight.

Problem solving process:
For the old question, the minimum two stacks are merged each time, and the direct loop to find O (N ^ 2) must be time-out. Therefore, you can use a small root heap for optimization, but the handwriting heap is a little troublesome. During the training in jianlan, we mentioned a better method:
Open two queues. The initial queue 1 is the weight of all the heaps. The combined weight is put into queue 2. Each time the first small one of the two queues is taken out, it is repeated, merge the two values into queue 2.

 

Question 3:
Question:
Let as few people as possible in a team, so that the team is arranged with the highest number of students, descending to the left and right.

Problem solving process:
Go from left to right, right to left, and find the longest ascending subsequence ending with personal I. You can obtain the maximum value from enumeration I. Time complexity O (N ^ 2 + n), or use another method for Binary optimization to (onlogn + n );

Question 4: (difficult)
The N-digit vertical addition is provided. Each digit is represented by a letter and the number represented by a letter is obtained. (The input data must be unique)

Problem solving process:
The first check is the search question, but N has a maximum of 26. The numbers represented by enumerative letters are O (N !) To add appropriate pruning.
The basic algorithm is to trace back, record the numbers represented by letters, and whether each number has been used. process each column from right to left. If the letters are unconfirmed, enumerate + DFS, and record the carry condition. If two letters in the same column have been determined, you can directly calculate the other one. If there is a conflict, you can trace back;
Without any pruning, you can finish the job at 9 o'clock and write it in about 50 minutes.
Pruning: because only the unique solution is ensured for the question data, a flag is used to record whether the answer has been found. If the flag is set to 1, return directly; 10 points can be passed.
Optimization 1: when it is worthwhile to enumerate uncertain letters, It is changed from n-1 to 0 (originally from 0 to n-1), which is much more efficient and can pass through 11 points, 12th points around MS, which is worse.
Then it got stuck for a long time. After half a day, Baidu felt that all the pruning work had been used, and the result was stuck in 1029 Ms...
Finally, I changed the string to the char array with luck. I submitted the string to 600 MS + AC. Is it much faster to retrieve an element from a char array than to retrieve an element from a string? Baidu did not mention this. This is probably the case.
The last point is disgusting for two hours. The main question is estimated to be 3 hours before the AC.
 
Gains:
Training patience .. Write B + code for the first time ..
Changing the cyclic variable size from small to small during DFS may greatly accelerate the running time.

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.