LightOj1285 - Drawing Simple Polygon(连接多边形各点)
题目链接: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(连接多边形各点)的更多相关文章
- LightOJ 1285 - Drawing Simple Polygon (几何,极角排序)
1285 - Drawing Simple Polygon PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- 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 ...
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数012,polygon,多边形
<zw版·Halcon-delphi系列原创教程> Halcon分类函数012,polygon,多边形 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换 ...
- CF EC 87 div2 1354 C2 Not So Simple Polygon Embedding 计算几何 结论
LINK:Not So Simple Polygon Embedding 搞了好久终于搞会了. 错误原因 没找到合适算边长的方法 要么就是边长算的时候算错了. 几何学的太差了 最后虽然把十边形的和六边 ...
- [svg 翻译教程]Polyline(折线)polygon(多边形)
原文: http://tutorials.jenkov.com/svg/polygon-element.html Polyline 虽然说这个 元素我没用过,但是还是蛮强大的,也翻译下 示例 < ...
- [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 ...
- e586. Drawing Simple Shapes
There are two ways to draw basic shapes like circles, ovals, lines, arcs, squares, rectangles, round ...
- POJ 3597 Polygon Division 多边形剖分
题目链接: http://poj.org/problem?id=3597 Polygon Division Time Limit: 2000MSMemory Limit: 131072K 问题描述 G ...
- e591. Drawing Simple Text
See also e575 The Quintessential Drawing Program. public void paint(Graphics g) { // Set the desired ...
随机推荐
- HDU 3065 (AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 题目大意:多个模式串,范围是大写字母.匹配串的字符范围是(0~127).问匹配串中含有哪几种模 ...
- HDU 2896 (AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2896 题目大意:多个模式串.多个匹配串.其中串的字符范围是(0~127).问匹配串中含有哪几个模式串 ...
- HDU 1312 (BFS搜索模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1312 题目大意:问迷宫中有多少个点被访问. 解题思路: DFS肯定能水过去的.这里就拍了一下BFS. ...
- HTML5离线应用无法更新的定位与解决
一.些许前提 最近在制作一个Web应用, 其中用到了HTML5的离线应用功能(offline application), 离线应用的概念就不再阐述, 可以查看这两篇文章: http://www.ibm ...
- 转 Web移动应用调试工具——Weinre
如今人们也越来越习惯在手机上浏览网页,而在手机上这些针对桌面浏览器设计的网页经常惨不忍睹.Web应用开发者需要针对手机进行界面的重新设计,但是手机上并没有称心如意的调试工具(如Firebug.web ...
- SSH整合配置二级缓存
一.了解 Hibernate的session提供了一级缓存,每个session,对同一个id进行两次load,不会发送两条sql给数据库,但session关闭时,一级缓存失效. 二级缓存是Sessio ...
- php phpeclipse + xampp 配置安装过程
就想test是否能配置成功,下载apache,php5.3,安装开始 apache的安装,一路next,遇到Server Information,随便填写即可,安装路径自己可选 php的安装,将下载的 ...
- 使用Eclipse自带Web Service插件(Axis1.4)生成Web Service服务端/客户端
创建一个名字为math的Java web工程,并将WSDL文件拷入该工程中 将Axis所需的jar包拷贝至WebRoot\WEB-INF\lib目录下,这些jar包会自动导入math工程中 一,生成W ...
- Xampp 添加 SSL
我的 XAMPP 没有找到这句话 ,直接添加 extension=php_openssl.dll 大概988行另外,需要配置 httpd-ssl.conf 文件(*\xampp\apache\con ...
- ci实现RBAC,详细解释原理和核心代码显示
代码实现不复杂,主要是思路的理解 RBAC是基于权限控制 1.权限结点管理 2.角色管理 3.管理员权限分配 结点管理就是把所有的分组 控制器 方法全部写入一个结点管理表 请注意在写一个动作比如,展示 ...