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 ...
随机推荐
- BZOJ2862 : 分糖果
二分答案$x$表示最大的一段的和. 设$f[i]$表示前$i$个最多分几段,满足最大的一段不超过$x$,若$f[n]\geq k$,则可行, 则$f[i]=\max(f[j])+1,sum[i]-su ...
- 移动端JS 触摸事件基础
一.手机上的触摸事件 基本事件: touchstart //手指刚接触屏幕时触发 touchmove //手指在屏幕上移动时触发 touchend //手指从屏幕上移开时触发 ...
- [Cocos2d-x For WP8]Transition 场景切换
在游戏中通常会打完了一关之后就会从当前的场景转换到另外一关的场景了,在Cocos2d-x中是由CCScene类表示一个场景.那么场景(CCScene)是为游戏中的精灵(CCSprite)提供了舞台,场 ...
- 【wikioi】1018 单词接龙
题目链接 算法:DFS+考你阅题 题目描述: 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中 ...
- hiho#14
军训去了没有打,回来看题跑. T1:hehe 注意X可能是实数233 #include<cstdio> #include<cctype> #include<queue&g ...
- dpi 、 dip 、分辨率、屏幕尺寸、px、density 关系以及换算(终结版)
首先,说下概念(网上很多帖子几个地方都搞混了,理一下): dip : device independent pixels ,设备无关像素. 我看很多帖子写的五花八门的,关于d的,什么display ...
- Programming with gtkmm 3
https://developer.gnome.org/gtkmm-tutorial/unstable/index.html.zh_CN 1. 序言 1.1. 本书 1.2. gtkmm 2. 安 ...
- opengl中层次建模的实现
1.显示列表的创建 例如: glNewList(listID,listMode); glutSolidCube(2.0); ...... glEndlist(); 可以创建一个listID显示列表,l ...
- lucene 3.0.2 搜索
1.lucene 词频 转载:http://mxdxm.iteye.com/blog/989031 lucene in action作为action系列,确实坚持了其实用性的特色.全书花了很大的篇幅来 ...
- POJ 2299 树状数组+离散化求逆序对
给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...