Luogu.com is a collaboration of all interesting and challenging Computer Science problems from contests or Olympics.
In order to enrich the problem set and satisfy the needs of CS lovers and geeks, from then on, I will post the English version of all the problems on it, each of which is strictly labeled as the original.
For convenience and submitting format, I will prepare random inputs in the pastebin, once you have completed your program, you can test each of them to get an individual output, then you should submit the final answer based on the outputs (e.g. the sum of all the outputs).
Requirments:
Generally, the running time should be less than for all given inputs. Although I've no methods to test the running time, the size of the input should help.
You can use any programming language as you want.
Your algorithm should be always correct for all the circumstances.
Welcome to challenge the problem set :)
Easy Math Editor
This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.
When posting on Brilliant:
*italics*
or_italics_
**bold**
or__bold__
paragraph 1
paragraph 2
[example link](https://brilliant.org)
> This is a quote
\(
...\)
or\[
...\]
to ensure proper formatting.2 \times 3
2^{34}
a_{i-1}
\frac{2}{3}
\sqrt{2}
\sum_{i=1}^3
\sin \theta
\boxed{123}
Comments
Luogu P1004 - Square access
As shown above, the image shows a N×N square, and some of them have treasures. The number denotes the value of treasures.
A thief wants to get as many treasures as possible, in order not to be caught by police, he can only start from the square of the upper left corner A, move rightwards and downwards without backing, to the square of lower right corner B. Along the way on each trial, he can take away the treasure of the squares. Unfortunately, he only has two trials, that is, he will go from A to B twice. Notice that on the second chance, the treasures taken away on the first chance can't be taken again.
Given the size of the square, N and the distribution of the values of treasures, find the maximum revenue the thief can get.
How to submit:
The pastebin below has 10 inputs. Each input has the format:
A number N(1≤N≤50), the size of the square.
N×N numbers, the distribution of the values of treasures.
You should output: A number M, the maximum revenue the thief can get.
Then submit the sum of all the outputs.
Inputs are here
Log in to reply
what is meant by trials does he go from A to B twice.
Log in to reply
Yes, exactly. The thief will go from A to B twice. Notice that on the second chance, the treasures taken away on the first chance can't be taken again.
Log in to reply
Log in to reply
Run time:O(f(n)), when a computer runs 1012 times per sec
Log in to reply
Log in to reply
@Alice Smith , please run the code above with inputs
3
033
333
330
and
2
00
20
Then tell me the inputs if you have time! Thank you! :)
Worst case time complexity: 50 times the 1249/1250th term of the 2500th row of the pascal triangle
@Vinayak Srivastava , here’s something you can try :)
Log in to reply
@Razing Thunder
Log in to reply
Log in to reply
Luogu P1005 - Matrix fetching game
Alice wants to play a matrix fetching game on a n×m matrix, where the elements of the matrix aij are all non-negative integers. The rules of the game are as follows:
Alice has m round of fetching.
For each fetching, she needs to take away one element from each row of the matrix.
Each element taken at a time can only be the first or last one of the row.
After each fetching, she will get a score. The score is the sum of all scores earned from fetching each row. The scores earned from each row is equal to e⋅2i, where e is the value of the element taken, and i is the ith round of fetching (labeled from 1 to m).
After m rounds, all of the elements of the matrix will be taken, and the score earned from each fetching will be added to get the final score.
Your goal is to find the optimal strategy for Alice to get maximum final score possible.
How to submit:
The pastebin below has 10 inputs. Each input has the format:
Two numbers n,m, the number of rows and columns of the matrix.
n×m numbers, the values of each element of the matrix.
You should output: A number M, the maximum final score Alice can get.
Then submit the sum of all of the outputs.
Input restrictions:
Input 1∼6: 1≤n,m≤30.
Input 7∼10: 1≤n,m≤80.
Inputs are here
Log in to reply
The logic is to choose the smallest em possible for each fetch, leaving the larger ones for the next. A for—if-else loop in python should do. Time complexity O(2mn).
Note that we can’t use C because it’s int is limited as ±231, but the total points are way larger.
Luogu P1008 - Triple hit
This problem has no inputs, and both mental calculation or programming are acceptable.
If 1,2,⋯,9 were split into 3 disjoint groups and we use them to make three 3-digit numbers x,y,z, such that x:y:z=1:2:3, then find all possible triples for (x,y,z).
How to submit:
Find all possible triples for (x,y,z), and submit ∑(x+2y+4z).
Log in to reply
are the groups disjoint and also does x,y,z all belong to each group or can two belong to the same.
Log in to reply
Yes, they are disjoint.
Luogu P1006 - Passing notes
Alice and Bob are good friends and classmates, they always talk about endless topics together. In a quality development activity, the classmates were arranged to make a matrix with m rows and n columns, and Alice and Bob were arranged at both ends of the diagonal of the matrix, so they could not talk directly. Fortunately, they can communicate by passing notes. The note will be passed to each other through many classmates. Alice sits in the upper left corner of the matrix with coordinates (1,1), and Bob sits in the lower right corner of the matrix with coordinates (m,n). The note passed from Alice to Bob can only be passed down or to the right, and the note passed from Bob to Alice can only be passed up or to the left.
During the activity, Alice hoped to pass a note to Bob, and also hoped that Bob would reply to her. Every classmate in the class can help them, but only once. That is to say, if the person helped when Alice handed the note to Bob, he would not help when Bob handed it to Alice, and vice versa.
There is one more thing that needs to be paid attention to. Each student in the class is willing to help with a high or low degree of goodwill (note: the degree of kindness of Alice and Bob is not defined, use 0 when entering), which is an integer between [0,100], and the larger the number, the more kind the student is. Alice and Bob hope to find as many kind students as possible to help pass the note, that is, to find two back and forth transmission paths, so that the sum of the degree of goodwill of the students on these two paths is maximized.
Now, please help Alice and Bob find such two paths.
How to submit:
The pastebin below has 10 inputs. Each input has the format:
Two numbers m,n, the number of rows and columns of the matrix.
The next m rows are an m×n matrix. The integer in the ith row and jth column of the matrix represents the degree of goodwill of the students sitting in the ith row and jth column. The n integers on each line are separated by spaces.
The output is an integer, which represents the* maximum* value of the sum of the degree of goodwill of the students who participated in passing the note on two roads back and forth.
Then submit the sum of all of the outputs.
Input restrictions:
Input 1∼3: 1≤n,m≤10.
Input 4∼10: 1≤n,m≤50.
Inputs are here
Note: This problem is very similar to Luogu P1004 - Square access, except that the two paths can't cross each other.
Luogu P1007 - Single-plank Bridge
The war has entered a critical time. You are the leader of the transport team, leading the transport force to deliver supplies to the front. The transportation task is as boring as a problem. You want to find some excitement, so you order your soldiers to admire the scenery on a log bridge in front, and you stay under the bridge to admire the soldiers. The soldiers were very angry because the single-plank bridge was very narrow and could only accommodate one person. If there are two people walking towards each other on the bridge to meet, then the two of them will not be able to bypass each other, and only one person can turn back and get off the bridge and let the other person pass first. However, multiple people can stay in the same location at the same time.
Suddenly, you received a message from the command center that enemy bombers are flying towards the single-plank bridge where you are! To be safe, your troops must withdraw the log bridge. The length of the single-plank bridge is L, and soldiers can only stay where the coordinates are integers. The speed of all soldiers is 1, but a soldier arrives at a position with coordinates 0 or L+1 at a certain moment, and he leaves the single-plank bridge.
Each soldier has an initial facing direction, they will walk in this direction at a constant speed, and will not change direction by themselves. However, if two soldiers meet face to face, they cannot pass each other, so they turn around and continue walking. It doesn't take any time to turn around.
Because of the previous anger, you can no longer control your soldiers. Even, you don't even know the direction each soldier is facing initially. Therefore, you want to know how long it takes at least for your troops to evacuate the log bridge. In addition, the headquarters is also arranging to stop the enemy's attack, so you also need to know how long it takes at most for your troops to evacuate the log bridge.
How to submit:
The pastebin below has 10 inputs. Each input has the format:
Line 1: An integer L, the length of the log bridge, where the coordinates are 1,2,⋯,L.
Line 2: An integer N, the number of soldiers.
Line 3: N integers, the initial coordinates for each soldier.
Output: Two integers L,R. L is the minimum time it takes for your troops to evacuate the log bridge, R is the maximum time it takes for your troops to evacuate the log bridge.
Then submit the sum of 2R−L of each output.
Inputs are here
Input restrictions:
No two soldiers are on the same coordinate initially.
N≤L≤5000.