Question A: Simulate the question. Just be careful.
Question B: DP
To give you a digital matrix, we need to go from the upper left corner to a path in the lower right corner. The number on this path is multiplied and the number at the end is the least.
The 0 at the end is produced by 2 and 5, so is it OK to think of the path with the least 2 or the path with the least 5?
Well, it's OK .*_*
Assume that the minimum number of numbers that walk from the upper left corner to the lower right corner of the page containing factor 2 is X, and the minimum number of five is Y, then the answer is Min (x, y ), that is to say, the number of the optimal solutions X and Y is the least proof: using the reverse proof method, we assume that the number of the optimal solutions contains a 2, B 5, a> X, B> y, the easy-to-obtain answer must be greater than min (x, y). Therefore, X and Y in the optimal solution must be the smallest.
View code
# Include <cstdio> # Include <Cmath> # Include < String > # Include <Cstdlib> # Include <Vector># Include <Map> # Include < Set > # Include <Iostream> # Include <Cstring> # Include <Algorithm> Using Namespace STD; Const Int INF = ~ 0u > 2 ; Const Int M = 1010 ; Int DP [m] [m] [ 2 ]; Int Min ( Int A, Int B ){ Return A <B? A: B ;} Int Main (){ Int N, I, J, K, X, Y, Pos; While (Scanf ( " % D " , & N )! = EOF) {pos =- 1 ; Memset (DP, 0 , Sizeof (DP )); For (I = 1 ; I <= N; I ++ ){ For (J = 1 ; J <= N; j ++ ) {Scanf ( " % D " , & X); y = X; If (X = 0 ) {Pos = I; Continue ;} While (Y % 2 = 0 ) {DP [I] [J] [ 0 ] ++; Y/= 2 ;} While (X % 5 = 0 ) {DP [I] [J] [ 1 ] ++, X/= 5 ;}}} For (I = 2 ; I <= N; I ++) {DP [I] [ 1 ] [ 0 ] + = DP [I- 1 ] [ 1 ] [ 0 ]; DP [I] [ 1 ] [ 1 ] + = DP [I- 1 ] [ 1 ] [ 1 ]; DP [ 1 ] [I] [0 ] + = DP [ 1 ] [I- 1 ] [ 0 ]; DP [ 1 ] [I] [ 1 ] + = DP [ 1 ] [I- 1 ] [ 1 ];} For (I = 2 ; I <= N; I ++ ){ For (J = 2 ; J <= N; j ++ ) {DP [I] [J] [ 0 ] + = Min (DP [I- 1 ] [J] [ 0 ], DP [I] [J- 1 ] [ 0 ]); DP [I] [J] [ 1 ] + = Min (DP [I- 1 ] [J] [ 1 ], DP [I] [J- 1 ] [1 ]) ;}} // Printf ("% d \ n", DP [N] [N] [1], DP [N] [N] [0]); String Ans; k = DP [N] [N] [ 0 ]> DP [N] [N] [ 1 ]; If (Pos! =- 1 && DP [N] [N] [k]) {printf ( " 1 \ n " ); For (I = 1 ; I <Pos; I ++) printf ( " D " ); For (I = 1 ; I <n; I ++) printf ( " R " ); For (I = Pos; I <n; I ++) printf (" D " ); Continue ;} I = N; j = N; While ( 1 ){ If (DP [I- 1 ] [J] [k] <DP [I] [J- 1 ] [K]) {I --; Ans + = " D " ;} Else {J -- ; Ans + = " R " ;} If (I = 1 ){ For (I = 1 ; I <j; I ++) ans + = " R " ; Break ;} If (J = 1 ){ For (J = 1 ; J <I; j ++) ans + =" D " ; Break ;}} Int Len = Ans. Length (); printf ( " % D \ n " , DP [N] [N] [k]); For (I = len- 1 ; I> = 0 ; I --) {Cout < Ans [I];} cout < Endl ;} Return 0 ;}
Question C: I will give you three circles, and find that the angle of a circle is equal to the angle of the three circles. If there are multiple circles, select the biggest point of the angle.
I used the climbing algorithm (Simulated Annealing), but it took a long time to adjust the parameters.
The evaluation function is the variance between the current point and the three circles. If a better solution is not obtained each time, the step is gradually reduced. If a better solution is obtained, the moving is always allowed.
When I go, I go up, down, left, right, and left. Maybe this is the reason why the answer is not accurate enough.
View code
# Include <cstdio> # Include <Cmath> Const Double EPS = 1E- 6 ; Int Dir [ 4 ] [ 2 ] = { 1 , 0 , 0 , 1 ,- 1 , 0 , 0 ,- 1 }; Struct Point { Double X, Y, R;} p [ 10 ]; Int SGN ( Double X ){ Return FABS (x) <EPS? 0 :( X> 0 ? 1 :- 1 );} Double Dist (point a, point B ){ Return SQRT (A. x-b.x) * (A. x-b.x) + (A. y-b.y) * (A. Y- B. Y ));} Double Judge (point TMP ){ Int I; Double Sum = 0 ; Double Ang [ 5 ]; For (I = 0 ; I < 3 ; I ++ ) {Ang [I] = Dist (P [I], TMP )/ P [I]. R; sum + = Ang [I];} sum /= 3 ; Double Vir = 0 ; For (I = 0 ; I < 3 ; I ++ ) Vir + = (ANG [I]-sum) * (ANG [I]-Sum ); Return Vir ;} Int Main (){ Int I, J, K; Double X = 0 , Y = 0 ; For (I = 0 ; I < 3 ; I ++ ) {Scanf ( " % Lf " , & P [I]. X, & P [I]. Y ,& P [I]. R); x + = P [I]. X; y + = P [I]. Y;} X /= 3 ; Y /= 3 ; Point S, T; S. x = X; S. Y = Y; Double Delta = 1 , Vir1, vir2; While (Delta> EPS) {vir1 = Judge (s ); For (I = 0 ; I < 4 ; I ++ ) {T. X = S. x + Delta * dir [I] [ 0 ]; T. Y = S. Y + Delta * dir [I] [ 1 ]; Vir2 = Judge (t ); If (Vir2 <vir1)Break ;} If (I = 4 ) Delta * = 0.82 ; // From 0.88 to 0.82 to get rid of the shadow of TLE. Else {S. x + = Delta * dir [I] [ 0 ]; S. Y + = Delta * dir [I] [ 1 ] ;}} If (Judge (s) <EPS) printf ( " %. 8lf %. 8lf \ n " , S. X, S. Y ); Return 0 ;}