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就可以了 // ...
随机推荐
- Python中optionParser模块的使用方法[转]
本文以实例形式较为详尽的讲述了Python中optionParser模块的使用方法,对于深入学习Python有很好的借鉴价值.分享给大家供大家参考之用.具体分析如下: 一般来说,Python中有两个内 ...
- 利用Jquery实现页面上div的拖动及位置保存
<script src="js/jquery.js.js" type="text/javascript"></script> <s ...
- 一些鲜为人知却非常实用的数据结构 - Haippy
原文:http://www.udpwork.com/item/9932.html 作为程序猿(媛),你必须熟知一些常见的数据结构,比如栈.队列.字符串.链表.二叉树.哈希,但是除了这些常见的数据结构以 ...
- 如何清除某条SQL的执行计划
如果遇到绑定窥探导致执行计划慢的情况,想要清除某条SQL的执行计划,让它硬解析,找了很久都没有找到直接操作share pool的方法(除非alter system flush shared_pool) ...
- Microsoft .NET Framework NGEN是神马东东?
简单的说,如果你的程序是基于.net framework的托管代码的话,NGEN服务能让你的程序第二次打开的速度变快. 赶脚是非常pad化的一项服务. http://msdn.microsoft.co ...
- C# 多线程的等待所有线程结束 用 ManualResetEvent 控制
using System; using System.Collections.Generic; using System.Threading; namespace ConsoleApplication ...
- UE用法
ueditor去除自动转换 ueditor在使用中发现很多问题.比如自动添加P标签,自动去除span,自动给li添加ul开始结束,自动把div转成P标签等等. 其实很多在百度上可以找到.这里总结下, ...
- 在.NET中使用EPPlus生成Excel报表 .
--摘抄自:http://blog.csdn.net/zhoufoxcn/article/details/14112473 在开发.NET应用中可能会遇到需要生成带图表(Chart)的Excel报表的 ...
- Relatives
Description Given n, a positive integer, how many positive integers less than n are relatively prime ...
- Chap5: question: 29 - 31
29. 数组中出现次数超过一半的数字. 方法a. 排序取中 O(nlogn). 方法b. partition 函数分割找中位数 >=O(n). 方法c. 设计数变量,扫描一遍 ...