Hard prob
Problem Statement |
|||||||||||||
| You have a rectangular piece of paper that’s divided into 1×1 cells, each of which has an integer value. The paper will be described by a vector <string> paper. The ith element of paper will be a space delimited list of integers, where the jth integer of the ith element of paper represents the value of the jth cell of the ith row of the paper.
You want to perform a sequence of folds on the paper, where you may fold anywhere along an axis that is in between two rows or columns of the paper. After performing a fold, we wish to model the folded paper as a new, flat piece of paper. We will do this by considering two overlapping cells as a single cell, with a value that is the sum of the individual cells. You wish to perform a sequence of folds such that the value of some single cell in the resulting piece of paper is as large as possible. Return this value. |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
| - | paper will contain between 1 and 12 elements, inclusive. | ||||||||||||
| - | Each element of paper will be a single-space delimited list of integers with no leading or trailing spaces. | ||||||||||||
| - | Each element of paper will contain between 1 and 12 integers, inclusive. | ||||||||||||
| - | Each element of paper will contain the same number of integers. | ||||||||||||
| - | Each element of paper will contain between 1 and 50 characters, inclusive. | ||||||||||||
| - | Each integer in paper will be between -100 and 100, inclusive. | ||||||||||||
| - | Each integer in paper will have no leading zeros. | ||||||||||||
| - | An integer in paper equal to zero will not have a preceding negative sign. | ||||||||||||
Examples |
|||||||||||||
| 0) | |||||||||||||
|
|||||||||||||
| 1) | |||||||||||||
|
|||||||||||||
| 2) | |||||||||||||
|
|||||||||||||
| 3) | |||||||||||||
|
|||||||||||||
| 4) | |||||||||||||
|
|||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Simple prob
Problem Statement
There is nothing more beautiful than just an integer number.
You are given an integer n. Write down n in decimal notation with no leading zeroes, and let M be the number of written digits. Perform the following operation exactly k times:
Choose two different 1-based positions, i and j, such that 1 <= i < j <= M. Swap the digits at positions i and j. This swap must not cause the resulting number to have a leading zero, i.e., if the digit at position j is zero, then i must be strictly greater than 1.
Return the maximal possible number you can get at the end of this procedure. If it’s not possible to perform k operations, return -1 instead.
Definition
Class:
TheSwap
Method:
findMax
Parameters:
int, int
Returns:
int
Method signature:
int findMax(int n, int k)
(be sure your method is public)
Constraints
-
n will be between 1 and 1,000,000, inclusive.
-
k will be between 1 and 10, inclusive.
Examples
0)
16375
1
Returns: 76315
The optimal way is to swap 1 and 7.
1)
432
1
Returns: 423
In this case the result is less than the given number.
2)
90
4
Returns: -1
We can’t make even a single operation because it would cause the resulting number to have a leading zero.
3)
5
2
Returns: -1
Here we can’t choose two different positions for an operation.
4)
436659
2
Returns: 966354
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
-
Recent
-
Links
-
Archives
- August 2009 (1)
- July 2009 (2)
- April 2009 (4)
- March 2009 (6)
- February 2009 (5)
- January 2009 (4)
- December 2008 (3)
- November 2008 (35)
- October 2008 (20)
-
Categories
-
RSS
Entries RSS
Comments RSS