Scrambled Polygon(poj2007极角排序输出凸包)

手把手教你玩转服务器芯片架构​专栏--​​3.5 实战案例:用SystemC搭建一个多核服务器芯片的NoC模型(含流量分配与延迟仿真)​ 通过SystemC搭建多核NoC模型,可深入验证流量分配策略与延迟特性。实际工程中需结合FPGA原型验证(如Xilinx Alveo)进行时序收敛分析,并通过参数化设计适配不同服务器芯片需求。 阅读详情

题意:给你一些点,让你按照极角的顺序输出凸包的顶点

思路:直接按照向量排序

按照向量叉乘的正负判断点所在的位置,类似于卷包裹的凸包,每次按照一条边排序,选择最外面的一条边,再按照选择的边在排序,再选直到点重合位置

这道题直接按照(0,0)点极角排序,如果极角相同选择最近的那个因为在一条直线上先选近的再选远的,如果选择远的那点的顺序都不对了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

struct Point
{
	double x,y;
	Point(double x = 0,double y = 0) : x(x),y(y) {}
};

typedef Point Vector;

Vector operator + (Vector a,Vector b) { return Vector(a.x+b.x,a.y+b.y) ;}
Vector operator - (Vector a,Vector b) { return Vector(a.x-b.x,a.y-b.y) ;}
Vector operator * (Vector a,double p) { return Vector(a.x*p,a.y*p) ;}
Vector operator / (Vector a,double p) { return Vector(a.x/p,a.y/p) ;}
const double eps = 1e-9;
const double PI = acos(-1.0);
double Dot(Vector a,Vector b) { return a.x*b.x + a.y*b.y ;}
double Length(Vector a) { return sqrt(Dot(a,a)) ;}
double Cross(Vector a,Vector b) { return a.x*b.y - a.y*b.x ;}
int dcmp(double x)
{
	if(fabs(x) < eps) return 0;
	else return x < 0 ? -1 : 1;
}
bool operator < (Point a,Point b) { return a.x < b.x || (a.x == b.x && a.y < b.y) ;}
bool operator == ( Point a, Point b) { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0 ;}
double Angle(Vector a,Vector b) { return acos( Dot(a,b) / Length(a) / Length(b) ) ;}
double Area(Point a,Point b,Point c) { return fabs(Cross(b-a,c-a))/2 ;}
Vector Rotate(Vector a,double rad) { return Vector(a.x*cos(rad) - a.y*sin(rad),a.x*sin(rad) + a.y*cos(rad) );}
Vector Normal(Vector a)
{
	double L = Length(a);
	return Vector(-a.y/L,a.x/L);
}

Point GetLineIntersection(Point p,Vector v,Point q,Vector w)
{
	Vector u =  p - q;
	double t = Cross(w,u) / Cross(v,w);
	return p + v*t;
}

bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{
	double c1 = Cross(a2-a1,b1-a1) ,c2 = Cross(a2-a1,b2-a1),c3 = Cross(b2-b1,a1-b1),c4 = Cross(b2-b1,a2-b1);
	return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3) *dcmp(c3) < 0;
}

bool OnSengment(Point p,Point a,Point b)
{
	return dcmp(Cross(p-a,b-a)) == 0 && dcmp(Dot(a-p,b-p) < 0);
}


double PolyArea(Point *p,int n)
{
	double area = 0;
	int i;
	for(i = 0; i < n; i++)
	{
		area += Cross(p[i]-p[0],p[i+1]-p[0]);
	}
	return area/2;
}
struct Line
{
	Point s,e;
};

int ConvexHull(Point* p,int n,Point* ch)
{
    sort(p,p+n);
    int m = 0;
    for(int i = 0; i < n; i++)
    {
        while( m > 1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <= 0) m--;
        ch[m++] = p[i];
    }

    int k = m;
    for(int i = n-2 ; i >= 0; i--)
    {
        while(m > k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <= 0) m--;
        ch[m++] = p[i];
    }
    if(n > 1) m--;
    return m;
}

Point p[1005];
bool cmp(Point a,Point b)
{
    double temp = Cross(a-p[0],b-p[0]);
    if(dcmp(temp) > 0) return true;
    else if(dcmp(temp) == 0 && dcmp( Length(a-p[0]) - Length(b-p[0]) ) <= 0) return true;
    else return false;
}

int main()
{
    int n = 0;
    while(scanf("%lf%lf",&p[n].x,&p[n].y) != EOF) n++;
    sort(p,p+n,cmp);
    for(int i = 0; i < n; i++)
    {
        printf("(%.0lf,%.0lf)\n",p[i].x,p[i].y);
    }
    return 0;
}


[QMT量化交易小白入门]-二、如何用miniQMT获取沪深A股的板块列表、历史行情数据和实时行情数据 本专栏主要是介绍QMT的基础用法,常见函数,写策略的方法,也会分享一些量化交易的思路,大概会写100篇左右。QMT的相关资料较少,在使用过程中不断的摸索,遇到了一些问题,记录下来和大家一起沟通,共同进步,自己淋过雨了,希望大家都有一把伞。 阅读详情

相关推荐

USB摄像头开发实战:从参数配置到图像采集的完整流程(Python+OpenCV)

本文详细介绍了USB摄像头开发的完整流程,从参数配置到图像采集,使用Python和OpenCV实现。内容涵盖硬件原理、环境配置、参数调优及高级优化技巧,帮助开发者解决常见问题如分辨率设置、帧率控制和灯光频闪等,提升开发效率。

star的博客 235

ACM-计算几何之Scrambled Polygon——poj2007

ACM 计算几何 Scrambled Polygon poj2007 几种极角排序

继续激情,继续奋斗。 2220

WIFI信号状态信息 CSI 特征提取篇之活动片段提取(五)

本环节是特征提取环节,起承上启下的作用:对上,应着数据处理完毕的信号,但是还不能直接进行分析,因为此时信号片段过长,对于活动识别而言,存在非许多目标片段(例如失败不规范的动作、休息间歇等);对下,具体采取何种活动片段提取策略,需要配合后续采取的活动识别算法进行(深度学习/机器学习,CNN/RNN/LSTM等等),不同的算法适配不同的数据形式,例如CNN一般用于识图,不需要关注时间顺序,LSTM则要求保留时间关系等等,所以本博客后续仅介绍几种分类思路。

Silver_777的博客 4537

POJ - 2007 Scrambled Polygon 【极角排序】

A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the vertices of the polygon. When one starts at any vertex of a clo...

slass-mot-odet 487

Pytorch学习笔记(III)——提取特征

目录一、引言二、具体步骤1、参数模型2、网络结构3、参数载入4、特征提取器5、读取图片三、完整代码 一、引言   深度学习在许多任务中主要充当着特征学习的作用,而学习完的特征才是后续应用的一个关键。本文将主要介绍,如何提取任意目标层的特征图。   本文以输入数据为图片为例。 二、具体步骤 1、参数模型 博主使用了ResNet50训练了一个人脸识别的网络   训练完成的深度学习模型,我们会保存一...

lockonlxf的博客 2643

博流BL602开发二 环境搭建与固件烧录实战

本文详细介绍了博流BL602 RISC-V芯片开发环境的搭建与固件烧录全流程。从Linux/WSL系统选择、RISC-V工具链配置、SDK获取,到编译首个Wi-Fi示例并生成固件镜像,再到通过命令行或图形化工具完成烧录及串口测试,提供了完整的实战指南和常见问题解决方案。

weixin_29175469的博客 451

POJ 2007 Scrambled Polygon 极角排序

题意: 给你一些点,这些点里面一定有(0,0)原点,并且没有第二象限中的点,这些点是一个凸包,让你按极角序输出这些点。 就排序,比较水,没凸包真扫兴 View Code #include #includestring.h> #include #include using namespace std; #define eps 1e-8 #define inf 1<<29

Nicolas 783

告别双系统!用Ventoy把Ubuntu 22.04装进U盘,打造你的随身开发环境(附保姆级避坑指南)

本文详细介绍了如何使用Ventoy将Ubuntu 22.04安装到U盘,打造便携式开发环境。通过即插即用的特性,开发者可以在任何x86电脑上快速启动完整的Ubuntu系统,无需配置双系统或虚拟机。文章提供了从硬件准备到系统优化的全流程指南,帮助用户高效创建随身开发环境。

weixin_31569671的博客 364

poj 2007 Scrambled Polygon 【极角排序】

Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7819   Accepted: 3719 Description A closed polygon is a figure bounded by a finite number

世界很大 528

【开发必备插件】iframe嵌套报“拒绝连接请求”的本地解决方法

关键词:iframe 拒绝连接、X-Frame-Options、Chrome 插件、前端调试、Allow X-Frame-Options前几天我在本地项目里调试一个第三方网站的嵌入页面时,遇到了一个非常经典的报错:xxx.com 拒绝了我们的连接请求。熟悉的老前端们一眼就知道——这是。但对于日常开发来说,我们经常需要在本地测试 iframe 嵌套外部页面(比如嵌第三方登录页、支付页、可视化报表系统等)。而线上站点配置了或DENY时,就会直接导致 iframe 加载失败。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1540

Python实现商品价格监控与波动分析爬虫项目

本文通过完整的代码示例和详细的技术讲解,展示了如何实现商品价格的自动监控和波动分析。该项目不仅适用于个人购物助手,还可以扩展为商家的竞品监控工具。通过结合数据抓取、存储、分析与可视化,能够帮助我们更好地理解市场趋势并做出优化决策。

2201_76125261的博客 1742

[极角排序]Scrambled Polygon POJ2007

A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the vertices of the polygon. When one starts at any vertex of a closed polygon and traverses each bounding line segment exa

Cloth的博客 236

6、探索音乐结构中的统一性:贝多芬《英雄交响曲》第一乐章的深度剖析

本文深入剖析了贝多芬《英雄交响曲》第一乐章的音乐结构,探讨其统一性的来源及表现形式。通过主题与动机、和声与调性、旋律与节奏、织体与动态等多方面的分析,揭示了这部作品在技术层面和情感表达上的卓越成就。

b9c0d的博客 518

【POJ2007】Scrambled Polygon(点集逆时针排序--极角排序/凸包--只适用于凸多边形)

题目地址:http://poj.org/problem?id=2007 解题思路: 每个点都和(0,0)点连接,构成一个向量,逆时针排序这些向量的极角逐渐增大。用atan2求解误差较大,会wa(;´༎ຶД༎ຶ`)舍弃该方法 排完序后的点集,任取相邻两个点A(在前),B(在后),定有Cross(A,B)>0,故cmp函数可写成: bool cmp(Point A, Point B) ...

Cassie_zkq的博客 530

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

poj 2007 Scrambled Polygon 极角排序

1 /** 2 极角排序输出,,, 3 主要atan2(y,x) 容易失精度,,用 4 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 return 1; 7 if(cross(a-tmp,b-tmp)==0) 8 return leng...

a18865477815的博客 173

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Scrambled Polygon POJ 2007 (极角排序 )

题目地址:http://poj.org/problem?id=2007 这是一道基础题,就是将点按照相对于(0,0)的极坐标位置排一下序,按逆时针方向。我们用叉积排序,而不用atan函数,因为atan函数在精度要求严格时会失效 可以看做是凸包的先行题。 #include <iostream> #include <stdio.h> #include <stdlib.h&...

呼吸 210

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

POJ 2007 Scrambled Polygon 凸包点排序逆时针输出

题意:如题 用Graham,直接就能得到逆时针的凸包,找到原点输出就行了,赤果果的水题~ 代码: /* * Author: illuz * Blog: http://blog.youkuaiyun.com/hcbbt * File: poj2007.cpp * Create Date: 2013-11-14 18:55:37 * Descripton:

水果君の日常 2080

POJ - 2007 Scrambled Polygon (凸包 极角排序)

Scrambled Polygon A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the vertices of the polygon. When one starts ...

YOONGI 251

poj2007-Scrambled Polygon (极角排序)

Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8924   Accepted: 4226 Description A closed polygon is a figure bounded by a finite number o

wangheng 337

【poj 2007】【凸包】 Scrambled Polygon

【poj 2007】【凸包】 Scrambled Polygon 题目 poj 2007 凸包模板题 将凸包上的点从(0,0)开始,逆时针输出 解题思路 Graham算法 确定最下面的一个点 然后其他点按极角排序(用tan来排) (y1/x1与y2/x2比较) 但是除法有精度问题 所以装换为乘法就是叉积 x1y2-x2y1 如果结果小于0,则点1在点2的逆时针 结果大于0在顺时针,为0则共线 下图为排完序后的 然后用栈维护,如果一个点比栈顶在更外面,踢栈顶,加入这个点 就是这种情况 代码 #inc

Y的博客 300

POJ 2007 Scrambled Polygon(凸包)

Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8912   Accepted: 4217 Description A closed polygon is a figure bounded by a finite number o

超越自我就是成功 394

poj2007——Scrambled Polygon

<br />对各个点进行极角排序,然后输出,搞定!<br />#include<stdio.h> #include<math.h> #include<string.h> #define max 55 struct node { int x,y; }min,g[max],stack[max]; int top,n; int pan(node yuan,node zhong,node last) { return (yuan.x-zhong.x)*(last.y-zhong.y)-

r_ax的专栏 566

poj2007 Scrambled Polygon【极角排序】

题目链接:http://poj.org/problem?id=2007 题意:好像就是给你个凸包,然后输出极角排序后的结果 解析:极角排个序就好?#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <string> using namespa

22h's Blog 645

POJ 2007 Scrambled Polygon(凸包,极角排序)

思路:没仔细看题,没想到居然是固定源点,我还以为说不固定,打乱,搞半天。。

weixin_48024524的博客 184

poj 2007 Scrambled Polygon(极角排序)

Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5363   Accepted: 2539 Description A closed polygon is a figure bounded by a finite number o

志当存高远 1038

poj 2007 Scrambled Polygon(计算几何)

Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6246   Accepted: 2956 Description A closed polygon is a figure bounded by a finite number

街角的花街糖 997
上一篇: Wall(poj1113凸包+圆的弧长)
下一篇: The Fortified Forest(poj1873位运算枚举+凸包)
leonharetd
博客等级 码龄15年 13粉丝 111原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值