Topcoder srm296 div1 report
Match date:Monday, 10000l 3, 2006
REPORT Date:Monday, 10000l 10,200 6
Preface:
It is time to reflect on the Performance of div1. This time, several pieces of challenge code were used, but the question still could not be done. It seems that the level is still poor.
Proble m 250-newalbum:
It seems that a simple question can be quickly solved using dynamic rules, but I thought it was simple and adopted a direct calculation method. I did not expect that this question contains so much dirty data.
From I = 1 to nsongs songs, the best way to handle each I is:
Best [I] = min (best [I], best [I-j] + 1) j = 1 .. Min (I, cdcapacity)
J indicates that J is placed in another CD after the best [I-j] cd. Of course, you must ensure that J cannot be divisible by 13.
Some people may have used this method, but some special cases should be taken into consideration. Including if the remaining 13 images are waiting for processing, and when the previous CD was set to 15 images, you can move them from the front, but if the previous CD was set to 14 images, it won't work.
Problem 500-stringreplacements:
The second question uses two delivery rules. After reading the report on solving the problem, I realized that the original recursive idea is so magical. It is really time to cultivate the recursive ability.
First, consider how to calculate the number of letters after a single letter changes n times. A dp array can be used. In the following formula, Mem is a DP array. t indicates the nth change, C indicates the change from the C Letter to the I letter. Move [I] [J] indicates the J-digit letter after the I letter is changed once.
Mem [T] [C] [I] = sum (MEM [T-1] [move [C] [k] [I]) k = 1 .. 3
Then we will consider how to obtain the number of letters from left to right. Since the number of letters after any letter is changed n times is 3 ^ N, therefore, you only need to calculate the relationship between 3 ^ N and left and right. Note that 3 ^ N may be out of the Integer Range:
Long [] solve (int c, int T, long left, long right) {// recursively calculates the solution between left and right
Long [] res = new long [3]; // Storage Solution
Long max = (long) math. Pow (3, T); // 3 ^ t indicates the maximum range
If (Left = Right & left = 0 & t = 0) {// only one letter is needed.
Res [c] ++; // and does not need to be changed
} Else if (left <= 0 & right> = max) {// The range of left and right is large.
Return getgen (C, T); // you can directly return the men
} Else if (left <= right ){
Int del = (INT) math. Pow (3, T-1); // evaluate 3 ^ (t-1), refers to the interval between the three after transformation //
For (INT I = 0; I <3; I ++) {// returns the three sub-letters in a loop.
Left = left <0? 0: Left; // left must be greater than or equal to 0
Right = right> Max? MAX: Right; // ensure that the value is smaller than or equal to the maximum possible value.
Long [] add = solve (move [C] [I], t-1, left, right); // recursively obtain a letter
For (Int J = 0; j <3; j ++ ){
Res [J] + = add [J]; // accumulate
}
Left-= del; // left is the left of the next letter.
Right-= del; // change to the right of the next letter
}
}
Return res;
}
Problem 1000-coloredbricks:
This question is cumbersome, testing programming speed and quantity. First, we can find 24 types of flipped pages. One plane can have six positions. The adjacent plane can be seen that there are four possibilities through one rotation. As long as a plane is fixed and the plane adjacent to it is fixed, six or four may be 24 cases.
// 301245 is the rotation from the front to the top
// 052413 is rotated from the left to the top
// 514302 is rotated from the left to the front
Int [] [] rotate = {3, 0, 1, 2, 4, 5}, {0, 5, 2, 4, 1, 3 },
{5, 1, 4, 3, 0, 2 }};
Int [] rot (INT [] X, int [] P); // rotation function. P is a value in rotate and returns the value after x conversion.
Void generaterotate () {// generate 24 possibilities
Int I, J, K, L = 0;
Int [] x = new int [] {0, 1, 2, 3, 4, 5 };
R = new int [24] [6];
For (I = 0; I <4; I ++ ){
X = rot (x, rotate [0]);
For (j = 0; j <4; j ++ ){
X = rot (x, rotate [1]);
Next: For (k = 0; k <4; k ++ ){
X = rot (x, rotate [2]);
For (INT [] E: R ){
If (arrays. Equals (E, x ))
Continue next;
}
R [L ++] = x. Clone ();
}
}
}
}
The next problem to be considered is the problem of coloring, which can be solved by brute force. Use a layer-7 for statement to enumerate all colors of a brick, and then calculate the color difference of the color for all input. The result is a minimum value. To calculate the color difference between a color and an input, 24 rotation is required.
Links:
My blog:
Http://blog.csdn.net/ray58750034/
My statistic:
Http://www.topcoder.com/stat? C = coder_room_stats & RD = 9817 & Cr = 20862220
SRM 289-problem set & analysis:
Http://www.topcoder.com/tc? Module = static & d1 = match_editorials & D2 = srm296