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 ...
随机推荐
- BZOJ4158 : [POI2007]Railway
论文题. 随便取个关键点,求出最短路树. 求出所有关键点组成的虚树,将两端都在虚树上的边保留. 对剩下的边求出最小生成树即可得到一组可行解. #include<cstdio> #inclu ...
- BZOJ1665 : [Usaco2006 Open]The Climbing Wall 攀岩
直接BFS貌似复杂度飞起来了,于是我们用k-d tree优化找点的过程即可.时间复杂度$O(n\sqrt{n})$. #include<cstdio> #include<algori ...
- CodeForces 359D (数论+二分+ST算法)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...
- POJ 1177 Picture(求周长并)
题目链接 看的HH的题解..周长有两部分组成,横着和竖着的,横着通过,sum[1] - last来计算,竖着的通过标记,记录有多少段. #include <cstdio> #include ...
- DWR入门教程
DWR(Direct Web Remoting)是一个WEB远程调用框架.利用这个框架可以让AJAX开发变得很简单.利用DWR可以在客户端利用JavaScript直接调用服务端的Java方法并返回值给 ...
- CentOS Git的还原和操作
$ git log --graph --oneline $ git reset --hard 版本号 用 reflog 挽救错误的重置 [jackluo@localhost demo]$ git re ...
- 兼容ie[6-9]、火狐、Chrome、opera、maxthon3、360浏览器的js本地图片预览
html代码: <div id="divPreview"> <img id="imgHeadPhoto" src="Images/H ...
- 各分支Linux的镜像下载地址
https://openstack.redhat.com/Image_resources http://fedoraproject.org/en/get-fedora#clouds https ...
- Vi问题
,ubuntu11.10下vi编辑器按i,左下方没有出现“输入模式”或者“insert”.在桌面环境下,用ctrl+alt+t调出命令行打开是这样,在第一控制台ctrl+alt+F1下打开,也是这样, ...
- JS采用正则表达式简单获取URL地址栏参数
GetUrlParam:function GetUrlParam(param){ var reg = new RegExp("(^|&)"+ param +"=( ...