POJ-1088 skiing DP

Source: Internet
Author: User

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  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.