编程大赛-6
|
Bitmap
|
For a given bitmap n×n, find an area of the maximum rectangular with the same number of 0s and 1s in it.
Input: (standard input)
+Line 1 contains an integer n, 1 ≦ n ≦ 200.
+Line i + 1, (where 1 <= i <= n), specifies i-th row of the bitmap i.e space separatedn bits.
Output: (standard output)
Your program should print out the maximum number of 0s and 1s which form a rectangular in the bitmap.
Example:
For sample input:
4
1 1 1 0
0 1 1 1
1 0 0 1
1 0 1 1
a correct output format:
6
Hint: The below red rectangle has a maximum area.
1 1 1 0
0 1 1 1
1 0 0 1
1 0 1 1
|
k-flat sequence
|
A sequence {ai} is called k-flat if for any two consecutive elements ai and ai+1, the following holds true: |ai - ai+1| ≦ k. For a given sequence, find the longest subsequence which is k-flat.
Input: (standard input)
+Line 1 contains two numbers n and k, 1 ≦ (n , k) ≦ 100000, where n denotes a number of elements of a sequence.
+Line 2 contains n positive integers - elements of a given sequence, all of them are not greater than 1000000000.
Output: (standard output)
Your program should print out k-flat subsequence with the maximum length. If there are more than one solution, print the one for which the last element has the smallest index, if there are more than one such solutions, print the one for which the next to last has the smallest index, etc.
Example:
For sample input:
6 3
2 9 7 2 5 8
a correct output format:
9 7 5 8
Hint: There are two 3-flat subsequences (k = 3) with four elements: 9 7 5 8 and 2 2 5 8. Both ends up with the same element (8), the next to last are also the same (5), but 7 is earlier (has smaller index) than 2 in the above example.
|
regular packets
|
To test a network, packets: 1, 2, 3, ..., n are sequentially transmitted to the destination three times in a row. A packet is called to be regular if there exists another packet which reaches the destination earlier in all three trials. Having the results of the three trials, find the sum of all regular packets.
Input: (standard input)
+Line 1 contains a number n, 1 ≦ n ≦ 100000, where n denotes a number of packets.
+Lines 2-4 contain results of each trial i.e.: n space-separated permutation of 1, 2, 3, ..., n.
Output: (standard output)
Your program should print out the sum of all regular packets.
Example:
For sample input:
5
4 3 2 5 1
4 2 5 1 3
5 1 2 4 3
a correct output format:
4
Hint: Packets 1 and 3 are regular because 5 was always faster than 1, and 4 was always faster than 3. Thus 1 + 3 = 4.

浙公网安备 33010602011771号