题目链接:http://lightoj.com/volume_showproblem.php?problem=1285

题意:给你一些点,然后把它们用一条线把它们连起来,构成一个多边形,不能有相交,必须用完所有的点,如果不能构成输出Impossible;

不能构成就是所有的点在一条直线上的时候;先按极角进行排序,然后倒着找到一个不再起点到终点那条线上的点,倒着连接起来;

#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N = ;
const double eps = 1e-;
const double PI = acos(-);
struct point
{
double x, y;
int Id;
point(){}
point(double x, double y) : x(x), y(y) {}
point friend operator - (const point &p1, const point &p2)///矢量p2p1;
{
return point(p1.x-p2.x, p1.y-p2.y);
}
double friend operator ^ (const point &p1, const point &p2)///p1×p2;
{
return p1.x*p2.y - p1.y*p2.x;
}
}; point p[N]; double Dist(point p1, point p2)
{
double dx = p1.x - p2.x, dy = p1.y - p2.y;
return sqrt(dx*dx + dy*dy);
}
int cmp1(point p1, point p2)///位置排序,找到最下方的;
{
if(p1.y != p2.y)
return p1.y < p2.y;
return p1.x < p2.x;///若有多个下方的找左边的;
}
int cmp2(point p1, point p2)///极角排序;若极角相同,距离近的在前面;
{
double k = (p1-p[])^(p2-p[]);
if( k>eps || (fabs(k)<eps && Dist(p1, p[]) < Dist(p2, p[]) ))
return ;
return ;
} int main()
{
int n, T, t=;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i=; i<n; i++)
{
scanf("%lf %lf", &p[i].x, &p[i].y);
p[i].Id = i;
} sort(p, p+n, cmp1);///p[0]为最下方靠左的点;
sort(p+, p+n, cmp2);///以p[0]为基点,按叉积进行排序; int flag = ;
for(int i=n-; i>; i--)
{
if(((p[n-]-p[])^(p[i]-p[]))!=)
{
flag = i;
break;
}
}
printf("Case %d:\n", t++);
if(flag==)
{
printf("Impossible\n");
continue;
}
reverse(p+flag+, p+n);
for(int i=; i<n; i++)
printf("%d%c", p[i].Id, i==n-?'\n':' ');
}
return ;
}

LightOj1285 - Drawing Simple Polygon(连接多边形各点)的更多相关文章

  1. LightOJ 1285 - Drawing Simple Polygon (几何,极角排序)

    1285 - Drawing Simple Polygon   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...

  2. 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 ...

  3. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数012,polygon,多边形

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数012,polygon,多边形 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换 ...

  4. CF EC 87 div2 1354 C2 Not So Simple Polygon Embedding 计算几何 结论

    LINK:Not So Simple Polygon Embedding 搞了好久终于搞会了. 错误原因 没找到合适算边长的方法 要么就是边长算的时候算错了. 几何学的太差了 最后虽然把十边形的和六边 ...

  5. [svg 翻译教程]Polyline(折线)polygon(多边形)

    原文: http://tutorials.jenkov.com/svg/polygon-element.html Polyline 虽然说这个 元素我没用过,但是还是蛮强大的,也翻译下 示例 < ...

  6. [javascript svg fill stroke stroke-width points polygon属性讲解] svg fill stroke stroke-width points polygon绘制多边形属性并且演示polyline和polygon区别讲解

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...

  7. e586. Drawing Simple Shapes

    There are two ways to draw basic shapes like circles, ovals, lines, arcs, squares, rectangles, round ...

  8. POJ 3597 Polygon Division 多边形剖分

    题目链接: http://poj.org/problem?id=3597 Polygon Division Time Limit: 2000MSMemory Limit: 131072K 问题描述 G ...

  9. e591. Drawing Simple Text

    See also e575 The Quintessential Drawing Program. public void paint(Graphics g) { // Set the desired ...

随机推荐

  1. BZOJ3570 : DZY Loves Physics I

    考虑两个质量均为m,速度分别v1.v2的小球发生完全弹性碰撞的影响: 由动能守恒得: $\frac{1}{2}mv_1^2+\frac{1}{2}mv_2^2=\frac{1}{2}mv_1'^2+\ ...

  2. VSPM虚拟串口使用

    (1)打开虚拟串口工具,当你设置好你程序中的串口信息后,打开程序中的串口,然后虚拟串口中所显示的就是程序的所提供的串口信息 (2)选中其中一个串口,修改管理信息,点击”重新连接“ , 直接在管理那里, ...

  3. 【wikioi】1229 数字游戏(dfs+水题)

    http://wikioi.com/problem/1229/ 赤裸裸的水题啊. 一开始我认为不用用完全部的牌,以为爆搜会tle.. 可是我想多了. 将所有状态全部求出,排序后暴力判断即可. (水题有 ...

  4. Splay 伸展树

    废话不说,有篇论文可供参考:杨思雨:<伸展树的基本操作与应用> Splay的好处可以快速分裂和合并. ===============================14.07.26更新== ...

  5. GC 基础

    = GC 基础 ===================== JAVA堆的描述如下: 内存由 Perm 和 Heap 组成. 其中 Heap = {Old + NEW = { Eden , from, ...

  6. Servlet的生命周期,并说出Servlet和CGI的区别,Servlet与JSP的区别

    一.Servlet 生命周期 1.加载 2.实例化 3.初始化 4.处理请求 5.销毁 二.Servlet与cgi的区别: Servlet处于服务器进程中,它通过多线程方式运行其service方法,一 ...

  7. 带你学C,带你飞——入门

  8. Camera Calibration and 3D Reconstruction

    3D RECONSTRUCTION WITH OPENCV AND POINT CLOUD LIBRARY http://stackoverflow.com/questions/19205557/op ...

  9. hdu-acm steps Monkey and Banana

    这道题是典型的dp题.首先是数据的处理上,因为每个长方体的3条不同长度的棱都可以作为高,因此一个长方体可以看成3个不同的长方体.从而将数据扩展为3*n,然后将所有的长方体以长度为第一排序条件,宽度为第 ...

  10. ThinkPHP几个配置文件的位置

    1.常用的ThinkPHP\Conf\convention.php 2.ThinkPHP/Lib/Behavior/ParseTemplateBehavior.class.php模板引擎相关配置