POJ 1696 Extreme angle sorting for maximum counterclockwise helix

Source: Internet
Author: User

Space Ant
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 4970 Accepted: 3100

Description

The most exciting space discovery occurred at the end of the 20th century. In 1999, scientists traced down a ant-like creature in the planet Y1999 and called it M11. It has only one eye on the left side of its head and just three feet all on the right side of its body and suffers from th REE Walking Limitations:
    1. It can not be turn right due to its special body structure.
    2. It leaves a red path while walking.
    3. It hates to pass through a previously red colored path, and never does that.

The pictures transmitted by the Discovery space ship depicts, plants in the Y1999 grow in special points on the planet . Analysis of several thousands of the pictures has resulted in discovering a magic coordinate system governing the Grow PO INTs of the plants. In the coordinate system with X and Y axes, no plants share the same x or Y.
An M11 needs to eat exactly one plant on each day to stay alive. When it eats one plant, it remains there for the rest of the day with no move. Next Day, it looks for another plant to go there and eat it. If it can not reach any other plant it dies by the end of the day. Notice that it can reach a plant in any distance.
The problem is to find a path for a M11 to let it live longest.
Input is a set of (x, y) coordinates of plants. Suppose A with the coordinates (XA, YA) are the plant with the least y-coordinate. M11 starts from point (0,ya) heading towards plant A. Notice, the solution path should not cross itself and all of the Turns should be counter-clockwise. Also Note that the solution is visit more than and plants located on a same straight line.

Input

The first line of the input was M, the number of test cases to be solved (1 <= M <= 10). For each test case, the first line was N, the number of plants in that test case (1 <= n <=), followed by N lines For each plant data. Each plant data consists of three integers:the first number are the unique plant index (1..N), followed by and positive in Tegers x and y representing the coordinates of the plant. Plants is sorted by the increasing order on their indices in the input file. Suppose that the values of coordinates is at most 100.

Output

Output should has one separate line for the solution of each test case. A solution is the number of plants on the solution path, and followed by the indices of visiting plants in the Er of their visits.

Sample Input

2101 4 52 9 83 5 94 1 75 3 26 6 37 10 108 8 19 2 410 7 6141 6 112 11 93 8 74 12 85 9 206 3 27 1 68 2 139 15 110 14 1711 13 1912 5 1813 7 314 10 16

Sample Output

10 8 7 3 4 9 5 6 2 1 1014 9 10 11 5 12 8 7 6 13 4 14 1 3 2

It seems that you can write it directly with a polar order.

Direct set of templates to write
1#include <iostream>2#include <stdio.h>3#include <string.h>4#include <algorithm>5#include <queue>6#include <map>7#include <vector>8#include <Set>9#include <string>Ten#include <math.h> One  A using namespacestd; -  - structPoint { the     Doublex, y; -     intidx; - Point () {} -PointintXinty): x (x), Y (y) {} +Pointoperator- (ConstPoint & A)Const { -         returnPoint (x-a.x, Y-a.y); +     } A     Double operator^ (ConstPoint & B)Const { at         returnX * b.y-y *b.x; -     } -     Double operator* (ConstPoint & A)Const { -         returnX * a.x + y *a.y; -     } -} p[ the]; in DoubleDist (Point A, point B) { -     returnsqrt ((a) * (A-b)); to } + intPos; - intCMP (Point A, point B) { the     Doubletemp = (A-p[pos]) ^ (b-P[pos]); *     if(temp = =0)returnDist (P[pos], a) <Dist (P[pos], b); $     Else if(Temp <0)return 0;Panax Notoginseng     Else return 1; - } the intMain () { +     intt, N; Ascanf"%d", &t); the      while(t-- ) { +scanf"%d", &n); -         Doublex, y; $          for(inti =0; I < n; i++) { $scanf"%D%LF%LF", &p[i].idx, &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]); -         } thepos =0; -          for(inti =1; I < n; i++) {WuyiSort (p + I, p +N, CMP); thepos++; -         } Wuprintf"%d", n); -          for(inti =0; I < n; i++) Aboutprintf"%d", P[I].IDX); $printf"\ n"); -     } -     return 0; -}

POJ 1696 Extreme angle sorting for maximum counterclockwise helix

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.