HDU 5020 Container Mark Slope

Source: Internet
Author: User

Test instructions: give you n points, let you find the maximum three points collinear, 1000 points

The puzzle: Obviously, the point 1000, the Normal enumeration O (N3), definitely not.

Method for map to record the slope of each point and other point lines, if the slope occurs more than 2, Num + = C (n,2);

Code:

#include <stdio.h> #include <iostream> #include <map>using namespaceStd;Map <double  ,  int> Mark; int Flag; struct Node {  int X,Y; }Cun[1005]; void Slove(Node A,Node b ) {  if  ( A.X ==B.X) {Flag ++ ; return  ;} Double K =(1.0 * (A.Y -B.Y)) / (1.0 * (A.X -B.X));Mark[K] ++; return  ; }int Slov (int A ) {  int K =A * (A-1) /2; return K; }  int  main() {  int T,N;scanf("%d",&T);  while (T--) {scanf("%d", &N);Mark.Clear();  for (int I =0;I<N;I++) {scanf("%d%d", &Cun[I].X, &Cun[I].Y); }  __int64 Num =0;Flag =0;  for (int I =0;I<N;I + +) {  for(int J =I+1;J<N;J++) {Slove (Cun[I],Cun[J]); }Map <double,  int;:: Iterator My_itr;  for (My_itr=Mark.Begin();My_itr!=Mark.End();++My_itr ) {  int K =My_itr -Second; if (K>=2)Num +=Slov(K); }  if( Flag>=2)Num +=Slov(Flag);Flag =0;Mark.Clear(); }Printf("%i64d\n",Num); } }

HDU 5020 Container Mark Slope

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.