The second question of DP has been done many times. This time, the memory-based search is not used. Instead, the search is sorted first and then the for loop is dynamically planned.
CodeAs follows:
# Include <cstdlib> # Include <Cstring> # Include <Cstdio> # Include <Cmath> # Include <Algorithm> Using Namespace STD; Int N; Struct Point { Double X, Y; Void Read () {scanf ( " % Lf " , & X ,& Y) ;}} P [ 105 ]; Int Main (){ Int T, RET, CA = 0 ; Scanf ( " % D " ,& T ); While (T -- ) {RET = 0x7fffffff + 1 ; Scanf ( " % D " ,& N ); For ( Int I = 0 ; I <n; ++I) {P [I]. Read ();} If (N = 1 ) {RET = 1 ;} Else { For ( Int I = 0 ; I <n; ++ I ){ For ( Int J = I +1 ; J <n; ++ J ){ // Enumerate all straight lines Int CNT = 2 ; Double X = P [J]. X- P [I]. X; Double Y = P [J]. Y- P [I]. Y; For ( Int K = J + 1 ; K <n; ++K ){ Double A = P [K]. X- P [I]. X; Double B = P [K]. Y- P [I]. Y; If (FABS (x * B-y * A) <1E- 6 ){ ++ CNT ;}} RET = Max (Ret, CNT) ;}} printf ( " Case % d: % d \ n " , ++ CA, RET );} Return 0 ;}