Let's take a look at some of the funny algorithms that may be obtained by the ctsc soy sauce competition.
Shape:
This is an artifact used for linear planning, because many things can be done with linear planning after reduction, so this algorithm is widely used.
For details about the specific practices, refer to the computing guide.
Here are some of my understandings.
The core operation is transform (I, j), which means that the I variable in J equation is used as the substitution variable, and the relaxation variable of J equation is used as the substitution variable to "cancel" All equations ".
The Code is as follows:
Procedure evaluate (I, j: longint ); VaR K, L, P: longint; Begin K: = B [I]; B [I]: = B [J + n + 1]; B [J + n + 1]: = K; Z: =-1/A [J, I]; C [0]: = 0; // You Hua For l: = 0 to n + 1 do begin If ABS (A [J, l])> E then begin
INC (C [0]); C [C [0]: = L; End;
A [J, l]: = A [J, l] * z;
End; A [J, I]: =-Z; For K: = 0 to t do if (k <> J) and (ABS (A [K, I])> E) then begin Z: = A [K, I];
For l: = 1 to C [0] Do
A [K, C [l]: = A [K, C [l] + A [J, C [l] * z; A [K, I]: = A [J, I] * z ;//!! * Z
End; End; |
Find the nearest variable with a positive coefficient in the target function to remove the variable.
Array B indicates where each variable is now"
Solution to basic initial solution failure: (some equations have constants <0)
Set an x0 and add an x0 after each equation. x0 is the basic variable (implicit x0
> = 0)
Then, select the equation I with the largest negative constant, and call forward (x0, I). Then, we will find that all constants are correct!
Then, because x0 does not actually affect the original linear planning, x0 should be equal to 0, so first get a target function to maximize
-X0: if the result of the final target type maximization is 0, it is correct. Otherwise, there will be no solution.
Through such a process (first running a linear plan), we can get a set of basic feasible solutions, and then what should we do?
In this question, only one set of feasible solutions is enough, so this is enough.
In addition, the solution that does not meet the non-negative limitation is to split each variable X1 into two, marked as x1' and x1 '', replace the original X1 with X1 '-X1 '', and specify that both X1 and X1'' have non-negative restrictions. This is equivalent conversion.
Main program call
J: = 0; A [0, n + 1]: =-1; For I: = 1 to t do begin A [I, n + 1]: = 1;
If a [I, 0] <A [J, 0] Then J: = I;
End; For I: = 1 to n + t + 1 do B [I]: = I; Round (n + 1, J ); While true do begin For I: = 1 to n + 1 do
If a [0, I]> E then
Break;
If a [0, I] <E then break;
Z: = 1e30;
For J: = 1 to t do If (A [J, I] <-E) and (-A [J, 0]/A [J, I] <z) then begin
Z: =-A [J, 0]/A [J, I]; K: = J;
End;
If z> 1e29 then break;
Round (I, K );
End; // If ABS (A [0, 0])> E then writeln ('fuck! '); For I: = 1 to t do If B [I + n + 1] <= n then
Ans [B [I + n + 1]: = A [I, 0];
For I: = 1 to n do writeln (ANS [I]: 0: 6 ); |
There are also some conversion techniques, which are very useful in computing. I will not repeat them here.
Simulated Annealing:
Classic non-perfect algorithms, low programming complexity, very cost-effective algorithms
Although this algorithm is basically messy, there are still a few tips
The first one is in Gu yanniu's paper. The probability that e ^ (-estimated function improvement volume/temperature) is acceptable is inferior, but this is not absolute, some questions may be better without accepting inferior solutions. In this case, simulated annealing degrades to randomization.
Another is that during each temperature enumeration, the number of enumerations is not necessarily a constant. It can be a function about temperature or a "Failure constant ", that is, only the inferior solution of this "Failure constant Times" is allowed.
In addition, it is the feature that Linux system can split the screen, so that an annealing program runs early, and then other questions are done in another work area to cheat the problem.
Another point is that the temperature is reduced at a time.
FFT:
The high-precision multiplication of O (nlogn) requires a lot of number theory knowledge. Although this algorithm may not be used in competitions, many of the number theory knowledge involved is still useful, for example, the original root or something.
However, this algorithm is not -_-!
PS: I don't know if there is any Changsha fever in Beijing ~