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. H20的题——[noip2003]银河英雄传(并查集)

    公元五八○一年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七九九年,银河系的两大军事集团在巴米利恩星域爆发战争.泰山压顶集团派宇 ...

  2. JSBinding+SharpKit / 脚本加密(JSC或Bytecode,参考cocos2d-js)

    现在已经可以编译JSC,目前只能在 Windows 下编译 JSC.这个功能是从 cocos2d-js 抄过来的,他应该也支持在Mac编译,但是我没有试过. 菜单:JSB | Compile all ...

  3. SNMP-配置文件详解

    当下的 SNMP 服务器通常用来被诸如 Nagios.Cacti.Zabbix 等监控软件收集数据,SNMP 的很多高级特性用的不是特别频繁.因而只需对 SNMP 进行一些简单.基础的配置以满足各种监 ...

  4. PHP 数组 foreach引用导致的bug

    <?php $arr = array('a', 'b', 'c'); foreach($arr as &$v) {} foreach($arr as $v) {} var_dump($a ...

  5. openssl 心脏滴血

    yum -y update openssl openssl verson rpm -q --changelog openssl | grep CVE-

  6. Java开发常用Linux命令

    1.查找文件 find / -name filename.txt根据名称查找/目录下的filename.txt文件. find . -name "*.xml"递归查找所有的xml文 ...

  7. linux网络环境下socket套接字编程(UDP文件传输)

    今天我们来介绍一下在linux网络环境下使用socket套接字实现两个进程下文件的上传,下载,和退出操作! 在socket套接字编程中,我们当然可以基于TCP的传输协议来进行传输,但是在文件的传输中, ...

  8. WEB-INF目录下的文件访问权限(待解决)

    对于Tomcat服务器而言,WEB-INF目录下的文件是不能通过在浏览器中直接输入地址的方式来访问. 原因:还不清楚

  9. itextSharp 附pdf文件解析

    一.PdfObject: pdf对象 ,有9种,对象是按照对象内涵来分的,如果按照对象的使用规则来说,对象又分为间接对象和直接对象.间接对象是PDF中最常用的对象,如前面对象集合里面的,所有对象都是间 ...

  10. 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败

    .NET导出Excel遇到的80070005错误的解决方法: 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出 ...