LightOJ 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'.
题意:
给了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 (几何,极角排序)的更多相关文章
- 简单几何(极角排序) POJ 2007 Scrambled Polygon
题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...
- LightOj1285 - Drawing Simple Polygon(连接多边形各点)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1285 题意:给你一些点,然后把它们用一条线把它们连起来,构成一个多边形,不能有相交,必 ...
- 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 ...
- POJ 2007 Scrambled Polygon [凸包 极角排序]
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8636 Accepted: 4105 ...
- poj 2007 Scrambled Polygon(极角排序)
http://poj.org/problem?id=2007 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6701 A ...
- POJ 2007 Scrambled Polygon (简单极角排序)
题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...
- poj 2007 Scrambled Polygon 极角排序
/** 极角排序输出,,, 主要atan2(y,x) 容易失精度,,用 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 retur ...
- POJ 2007 Scrambled Polygon(简单极角排序)
水题,根本不用凸包,就是一简单的极角排序. 叉乘<0,逆时针. #include <iostream> #include <cstdio> #include <cs ...
- Scrambled Polygon POJ - 2007 极角排序
题意: 给你n个点,这n个点可以构成一个多边形(但是不是按顺序给你的).原点(0,0)为起点,让你按顺序逆序输出所有点 题解: 就是凸包问题的极角排序 用double一直Wa,改了int就可以了 // ...
随机推荐
- mysql主从复制问题之主从两端binlog日志不同步解决方案
主操作: 进入主的数据库查看状态: mysql> show master statusG; *************************** 1. row **************** ...
- Type Project has no default.properties file! Edit the project properties to set one.
Description Resource Path Location Type Project has no default.properties file! Edit the project pro ...
- Makefile中的特殊宏定义以及实用选项
Makefile中的一些特殊宏定义的名字跟shell中的位置变量挺相似的. $? 当前目标所依赖的文件列表中比当前目标文件还要新的文件 $@ 当前目标我名字 $< 当前依赖文件的名 ...
- IRaster、IRasterlayer、IRasterdataset之间的转换
IRaster.IRasterlayer.IRasterdataset之间的转换 layer = axMapControl.get_Layer(0);//需要的栅格图层 IRasterLayer ra ...
- Spark SQL External Data Sources JDBC官方实现写测试
通过Spark SQL External Data Sources JDBC实现将RDD的数据写入到MySQL数据库中. jdbc.scala重要API介绍: /** * Save this RDD ...
- C#中截取字符串的几种方法
1.根据单个分隔字符用split截取 例如 复制代码代码如下: string st="GT123_1"; string[] sArray=st.split("_&qu ...
- mysql中中文乱码问题
作用:约束用来保证数据有效性和完整性 . 定义主键约束 主键约束 primary key : 信息记录某个字段可以唯一区分其他信息记录,这个字段就可以是主键 (唯一 非空) primary key ...
- 如何定义DATATABLE,同时赋值
//定义一个Table DataTable dt=new DataTable("yeji"); DataRow dr; DataColumn dc; //添加第0列 dc=new ...
- java学习第9天
形式参数和返回值的问题 (1)形式参数: 类名:需要该类的对象 抽象类名:需要该类的子类对象 接口名:需要该接口的实现类对象 (2)返回值类型: 类名:返回的是该类的对象 抽象类名:返回的是该类的子类 ...
- VS2013使用EF6连接MySql
前提:a.安装MySql的VS插件(版本请下载最新版) 我用的是:mysql-for-visualstudio-1.1.4 b.安装用于.net连接程序 mysql-connector-net-6. ...