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就可以了 // ...
随机推荐
- VS xsd Class
1.将xsd 文件 转成 实体文件 xsd FilePath(*.xsd) /c 2.将 xml 文件 转成 xsd 文件 xsd FilePath(*.xml)
- [系统设计/开发] APP密钥签发服务器
公司的信息安全制度要求对产线的APP进行严格的签发管理,确保密钥.密码的安全. 之前的做法是: 建立一台独立的签发主机: 密钥放在签发主机上,由专人管理: 构建系统每构建出一个产线APP,都要手动拷贝 ...
- [转]App Store 审核、限时免费、排行、推荐机制技巧精华汇总
在 App Store 上,什么样的应用会得到推荐? 这个问题问的非常大,而且编辑推荐很多个人元素在里面,我试着用推荐Ovi Store应用的思路来回答一下: 关于应用: 1.首先这个应用最基本的功能 ...
- ADF_Controller系列3_通过创建ADF Menu作为页面向导(Part1)
2015-02-15 Created By BaoXinjian
- python(24)urlencode和urldecode
当url地址含有中文,或者参数有中文的时候,这个算是很难正常了,但是把这样的url作为参数传递的时候(最常见的callback),需要把一些中文甚至‘/’做一下编码转换. 一.urlencode ur ...
- 【php】assert函数的用法
[php]assert函数的用法 http://www.douban.com/note/217557007/ 2012-06-01 10:32:37 assert这个函数在php语言中是用来判断一 ...
- protoc 命令参数
protoc 命令的获得 源码在 https://github.com/google/protobuf , 如果不想自己编译获得最新版本,则可以下载官方编译好的各个平台的,下载地址:https://g ...
- OPTIMIZE TABLE的作用--转载
当您的库中删除了大量的数据后,您可能会发现数据文件尺寸并没有减小.这是因为删 除操作后在数据文件中留下碎片所致.Discuz! 在系统数设置界面提供了数据表优化的功能,可以去除删除操作后留下的数据文件 ...
- Chap5:32– 34
32. 从 1 到 n 整数中 k (0,1, 2, 3, 4, 5, 6, 7, 8, 9)出现的次数. 时间 O(log10N) A. 当 K != 0 时: 以 n = 2014,K = 1 ...
- COSBench性能测试配置--一张图说明一切
COSBench性能测试配置--一张图说明一切: 测试配置,并发数,运行时间设置