poj 2007
来源:互联网 发布:linux grub引导 stage 编辑:程序博客网 时间:2024/05/18 14:26
题目概述
以任意顺序给定一个凸N边形的所有顶点坐标x,y,其中必然包含原点,求其顶点相对于原点的逆时针排序
除了原点,不会有任何点在坐标轴,也不会出现三点共线
时限
1000ms/3000ms
输入
每行两个整数x,y,第一行一定是0 0,数据只有一组,输入到EOF结束
限制
3<=N<=50;-1000< x,y<1000
输出
每行一个字符串
(x,y)
其中x,y描述一个顶点的位置,相对于原点,按逆时针顺序输出所有点,第一个点一定是原点
样例输入
0 0
70 -50
60 30
-30 -50
80 20
50 -60
90 -20
-30 -40
-10 -60
90 10
样例输出
(0,0)
(-30,-40)
(-30,-50)
(-10,-60)
(50,-60)
(70,-50)
(90,-20)
(90,10)
(80,20)
(60,30)
讨论
计算几何,但很可惜不是凸包,因为题目已经明确说过了,因此只要利用向量积为正排序就可以了
一开始还以为有多组数据……
题解状态
168K,0MS,C++,702B
题解代码
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;#define INF 0x3f3f3f3f #define MAXN 53#define memset0(a) memset(a,0,sizeof(a))#define EPS 1e-6struct Point{ int x, y;}points[MAXN];int xp(int x1, int y1, int x2, int y2, int x3, int y3){ return (x1 - x2)*(y3 - y2) - (y1 - y2)*(x3 - x2);}bool pred(Point &a, Point &b){ return xp(a.x, a.y, 0, 0, b.x, b.y) > 0;}int main(void){ //freopen("vs_cin.txt", "r", stdin); //freopen("vs_cout.txt", "w", stdout); int N = 0;//顶点数 while (~scanf("%d%d", &points[N].x, &points[N].y))//input N++; sort(points + 1, points + N, pred);//第一个点一定是原点 不用排序 排了就WA for (int p = 0; p < N; p++) printf("(%d,%d)\n", points[p].x, points[p].y);//output}
0 0
- poj 2007
- POJ-2007
- poj 2007
- poj 2007 Scrambled Polygon
- poj 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon
- POJ 2007 简单几何
- POJ 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon
- poj 2007 Scrambled Polygon
- POJ 2007 Scrambled Polygon .
- POJ 2007 Scrambled Polygon
- poj 2007 Scrambled Polygon
- POJ
- poj
- POJ
- 无论是玩游戏还是交女朋友都需要预热
- Linux启动时出现 an error occurred during the file system check错误
- Maven本地资源库
- abp构建Web API服务
- Maven根据不同环境打包不同配置文件
- poj 2007
- eclipse环境搭建ssh(Struts2+Spring2.5+Hibernate3)框架小谈(上)
- 服务器端技术概述
- Mysql自学笔记四
- 测试
- GitHub使用(一)
- Netty的高性能架构之道
- Matplotlib中文乱码问题的解决办法
- ConcurrentHashMap实现原理--上