1285 - Drawing Simple Polygon
Time Limit: 2 second(s) Memory Limit: 32 MB

Given set of points in the plane, your task is to draw a polygon using the points. You have to use all the points. To be more specific, each point of the set has to be a vertex of the polygon, and the polygon must not have any other vertices. No two line segments of the polygon may have any point in common, except for the middle vertex of two consecutive line segments. For example, given the points on the left-hand side, a valid polygon is shown on the right-hand side:

   

You can assume that, no two points will share the same location.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer n (3 ≤ n ≤ 2000), denoting the number of points. The next line contains the co-ordinates of the points. Each point is specified by two integer x y in the range [-104, 104].

Output

For each case, print the case number in a single line first. In the next line print 'Impossible' if no solution can be found. Otherwise print a permutation of the numbers 0 to n-1. Each of these numbers represents the index of a point, in the same order as given in the input. When drawing line segments between consecutive points in the order given by this permutation, the result must be a valid polygon. Insert a single space between two integers.

Sample Input

Output for Sample Input

2

4

0 0 2 0 0 1 1 0

5

0 0 10 0 10 5 5 -1 0 5

Case 1:

0 3 1 2

Case 2:

2 1 3 0 4

Note

This is a special judge problem; wrong output format may cause 'wrong answer'.


PROBLEM SETTER: SABBIR YOUSUF SANNY
SPECIAL THANKS: JANE ALAM JAN (DESCRIPTION, SOLUTION, DATASET)

题意:

给了n个点,让连成一个多边行。

按照极角排序下,然后搞,就是最好一个点共线的要倒序下。

注意极角排序,第一个点不要排(坑了好久,第一个点排了可能会有问题的)

 /* ***********************************************
Author :kuangbin
Created Time :2014/4/22 17:41:27
File Name :E:\2014ACM\专题学习\计算几何\凸包\LightOJ1285.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int maxp = ;
struct Point
{
int x,y;
int index;
Point(){}
Point(int _x,int _y)
{
x = _x;
y = _y;
}
void input()
{
scanf("%d%d",&x,&y);
}
bool operator < (Point b)const
{
return x == b.x ? y < b.y:x < b.x;
}
Point operator - (const Point &b)const
{
return Point(x-b.x,y-b.y);
}
int operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
int len2()
{
return x*x + y*y;
}
};
Point p[maxp];
bool cmp(Point a,Point b)
{
int tt = (a-p[])^(b-p[]);
if(tt == )
return (a-p[]).len2() < (b-p[]).len2();
else return tt > ;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int n;
scanf("%d",&T);
int iCase = ;
while(T--)
{
iCase++;
scanf("%d",&n);
for(int i = ;i < n;i++)
{
p[i].input();
p[i].index = i;
}
sort(p,p+n);
sort(p+,p+n,cmp);
int tmp = ;
for(int i = n-;i > ;i--)
if(( (p[n-]-p[])^(p[i]-p[]) ) != )
{
tmp = i;
break;
}
printf("Case %d:\n",iCase);
if(tmp == )
printf("Impossible\n");
else
{
reverse(p+tmp+,p+n);
for(int i = ;i < n;i++)
{
printf("%d",p[i].index);
if(i < n-)printf(" ");
else printf("\n");
}
}
}
return ;
}

LightOJ 1285 - Drawing Simple Polygon (几何,极角排序)的更多相关文章

  1. 简单几何(极角排序) POJ 2007 Scrambled Polygon

    题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...

  2. LightOj1285 - Drawing Simple Polygon(连接多边形各点)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1285 题意:给你一些点,然后把它们用一条线把它们连起来,构成一个多边形,不能有相交,必 ...

  3. Drawing Simple Polygon(Create Simple Polygon from unordered points by angle sorting)

    Keywords: 极角排序, Simple Polygon Generation Given set of points in the plane, your task is to draw a p ...

  4. POJ 2007 Scrambled Polygon [凸包 极角排序]

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8636   Accepted: 4105 ...

  5. poj 2007 Scrambled Polygon(极角排序)

    http://poj.org/problem?id=2007 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6701   A ...

  6. POJ 2007 Scrambled Polygon (简单极角排序)

    题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...

  7. poj 2007 Scrambled Polygon 极角排序

    /** 极角排序输出,,, 主要atan2(y,x) 容易失精度,,用 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 retur ...

  8. POJ 2007 Scrambled Polygon(简单极角排序)

    水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cs ...

  9. Scrambled Polygon POJ - 2007 极角排序

    题意: 给你n个点,这n个点可以构成一个多边形(但是不是按顺序给你的).原点(0,0)为起点,让你按顺序逆序输出所有点 题解: 就是凸包问题的极角排序 用double一直Wa,改了int就可以了 // ...

随机推荐

  1. JavaScript 图片的上传前预览(兼容所有浏览器)

    功能描述 通过 JavaScript 实现图片的本地预览(无需上传至服务器),兼容所有浏览器(IE6&IE6+.Chrome.Firefox). 实现要点   ● 对于 Chrome.Fire ...

  2. 有向图强连通分量 Tarjan算法

    [有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly connected).如果有向图G的每两个顶点都强连通,称G是一个强连通图.非强连通图有向图的极 ...

  3. java io系列14之 DataInputStream(数据输入流)的认知、源码和示例

    本章介绍DataInputStream.我们先对DataInputStream有个大致认识,然后再深入学习它的源码,最后通过示例加深对它的了解. 转载请注明出处:http://www.cnblogs. ...

  4. 安装初始化mysql后,默认几个库介绍

    背景介绍:  当我们安装初始化mysql后,默认建了几个数据库,那么这些数据库有什么作用呢?mysql> show databases;+--------------------+| Datab ...

  5. Linux下编译安装PCRE库

    备注:如果没有root权限,使用 --prefix 指定安装路径 ./configure --prefix=/home/work/tools/pcre-8.xx =================== ...

  6. Action、Action<T>、Func<T> 匿名函数的写法

    void ht_HLB_Set(Dictionary<int, int> dic) { //匿名函数 Action<int> fun = (int jhShare_Iid) = ...

  7. JAVA自定义事件监听完整例子---sunfruit[转]

    http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763105392230e54f733628a854d2c90c05f9313071601 ...

  8. IntelliJ IDEA热加载自动更新(Update classes and resources )

          IntelliJ IDEA默认文件是自动保存的,但是手头有个项目jsp文件改动后,在tomcat中不能立即响应变化.想要jsp文件改动后立刻看到变化,可以通过修改配置来实现.       ...

  9. ruby的加密方法整理(des rsa加密 加签)

    # coding:utf-8require 'openssl'require 'base64'#des加密并且base64编码def des_encrypt des_key, des_text des ...

  10. WebApi:过滤器的种类

    WebApi:筛选器的种类 授权筛选器:这些筛选器用于实现IAuthorizationFilter和做出关于是否执行操作方法(如执行身份验证或验证请求的属性)的安全决策.AuthorizeAttrib ...