UVA lining up (violence)

Source: Internet
Author: User

This topic I was violent made out, the complexity is n^3, because the array is more than 700 groups, about can use this complexity, although strictly speaking more than 500

is normal, each time is to select two coordinates and then determine a line, and then traverse the other points, with the cross-product form to decide whether in a straight line is OK

, the internet said can be used to solve the order of the polar angle, the complexity is n^2logn but I looked at and did not want to learn the desire ... Learn it later,,, and use it.

The SSCANF function, to see what others are using, is to match the desired type in an array ... This problem is the input of the pit. Between each of the two outputs

There is a blank line, and the last group cannot be followed by a blank line ... and the coordinate input has a blank line before ...

Post code:

#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h>using namespace Std;struct node{int I,j;} A[705];int cmp (const void *a,const void *b) {if ((node *) a)->i! = ((node *) b)->i) return ((node *) a)->i-((node *) b)->i;return (node *) a)->j-((node *) b)->j;} int main () {int t,i,j,k;cin >> T;getchar (); GetChar (); while (t--) {int i = 1;char b[100];int n = 1;while (gets (b)!=null) {if (b[0] = = ' + ') break;            SSCANF (b, "%d%d", &A[N].I,&A[N].J);            n++;} n = N-1;qsort (a+1,n,sizeof (a[0]), CMP), int max = 2;for (i=1; i<=n; i++) {for (j=i+1; j<=n; J + +) {int sum = 2;for (k=j+1; k <=n; k++) {if ((A[J].J-A[I].J) * (a[k].i-a[j].i) = = (A[K].J-A[J].J) * (a[j].i-a[i].i)) {sum++;}} if (Sum > max) max = sum;}} cout << Max << endl;if (T! = 0) cout << Endl;} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UVA lining up (violence)

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.