Space Ant-poj 1696 (convex bag)

Source: Internet
Author: User

The main topic: give some hash point and then the initial point is the coordinates of the bottom of the leftmost point, and then only go to the left, to find out the maximum number of points can pass, the serial number output.  Analysis: First find out the initial point, and then constantly sort out the nearest bump .... Complexity is N^2*log (n) .... Not a little more, so feel free to play. The code is as follows:=========================================================================================================== ==========
#include <stdio.h>#include<math.h>#include<algorithm>using namespacestd;Const intMAXN =107;Const DoubleEPS = 1e-8;structpoint{Doublex, y; intID; Point (Doublex=0,Doubley=0): X (x), Y (y) {} pointoperator- (ConstPoint &tmp)Const{        returnPoint (x-tmp.x, ytmp.y); }    Double operator*(ConstPoint &tmp)Const{        returnx*tmp.x + y*tmp.y; }    Double operator^(ConstPoint &tmp)Const{        returnx*tmp.y-y*tmp.x; }};DoubleDist (Point A, point B) {returnsqrt (A-B) * (Ab));} Point P[MAXN];intKi;BOOLCMP (Point A, point B) {DoubleT = (A-p[ki]) ^ (b-P[ki]); if(Fabs (T) <EPS)returnDist (P[ki], a) <Dist (P[ki], b); returnT >EPS;}intMain () {intT; scanf ("%d", &T);  while(t--)    {        intI, N; scanf ("%d", &N);  for(intI=0; i<n; i++) {scanf ("%D%LF%LF", &p[i].id, &p[i].x, &p[i].y); if(P[i].y < p[0].y | | (p[i].y==p[0].y && p[i].x < p[0].x)) swap (P[i], p[0]); } ki=0;  for(i=1; i<n; i++, ki++) {sort (P+i, p+N, CMP); } printf ("%d", N);  for(i=0; i<n; i++) printf ("%d", p[i].id); printf ("\ n"); }    return 0;}

Space Ant-poj 1696 (convex bag)

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.