poj--2007--Scrambled Polygon(数学几何基础)
| Time Limit: 1000MS | Memory Limit: 30000KB | 64bit IO Format: %I64d & %I64u |
Description
bounding line segment exactly once, one comes back to the starting vertex.
A closed polygon is called convex if the line segment joining any two points of the polygon lies in the polygon. Figure 1 shows a closed polygon which is convex and one which is not convex. (Informally, a closed polygon is convex if its border doesn't have
any "dents".)
The subject of this problem is a closed convex polygon in the coordinate plane, one of whose vertices is the origin (x = 0, y = 0). Figure 2 shows an example. Such a polygon will have two properties significant for this problem.
The first property is that the vertices of the polygon will be confined to three or fewer of the four quadrants of the coordinate plane. In the example shown in Figure 2, none of the vertices are in the second quadrant (where x < 0, y > 0).
To describe the second property, suppose you "take a trip" around the polygon: start at (0, 0), visit all other vertices exactly once, and arrive at (0, 0). As you visit each vertex (other than (0, 0)), draw the diagonal that connects the current vertex with
(0, 0), and calculate the slope of this diagonal. Then, within each quadrant, the slopes of these diagonals will form a decreasing or increasing sequence of numbers, i.e., they will be sorted. Figure 3 illustrates this point.
Input
is an integer in the range -999..999. The vertex on the first line of the input file will be the origin, i.e., x = 0 and y = 0. Otherwise, the vertices may be in a scrambled order. Except for the origin, no vertex will be on the x-axis or the y-axis. No three
vertices are colinear.
Output
output will determine a trip taken along the polygon's border, in the counterclockwise direction. The output format for each vertex is (x,y) as shown below.
Sample Input
0 0
70 -50
60 30
-30 -50
80 20
50 -60
90 -20
-30 -40
-10 -60
90 10
Sample Output
(0,0)
(-30,-40)
(-30,-50)
(-10,-60)
(50,-60)
(70,-50)
(90,-20)
(90,10)
(80,20)
(60,30) 直接按照计较排序就好#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define MAX 10010
struct node
{
double x,y;
}point[MAX];
bool cmp(node a,node b)
{
if(a.x*b.y-a.y*b.x>0)
return true;
return false;
}
int main()
{
int n=0;
while(scanf("%lf%lf",&point[n].x,&point[n].y)!=EOF)
{
n++;
}
sort(point+1,point+n,cmp);
for(int i=0;i<n;i++)
cout<<"("<<point[i].x<<","<<point[i].y<<")"<<endl;
return 0;
}
poj--2007--Scrambled Polygon(数学几何基础)的更多相关文章
- POJ 2007 Scrambled Polygon 凸包
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7214 Accepted: 3445 ...
- POJ 2007 Scrambled Polygon [凸包 极角排序]
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8636 Accepted: 4105 ...
- POJ 2007 Scrambled Polygon 极角序 水
LINK 题意:给出一个简单多边形,按极角序输出其坐标. 思路:水题.对任意两点求叉积正负判断相对位置,为0则按长度排序 /** @Date : 2017-07-13 16:46:17 * @File ...
- poj 2007 Scrambled Polygon(极角排序)
http://poj.org/problem?id=2007 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6701 A ...
- ●POJ 2007 Scrambled Polygon
题链: http://poj.org/problem?id=2007 题解: 计算几何,极角排序 按样例来说,应该就是要把凸包上的i点按 第三像限-第四像限-第一像限-第二像限 的顺序输出. 按 叉积 ...
- 简单几何(极角排序) POJ 2007 Scrambled Polygon
题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...
- POJ 2007 Scrambled Polygon (简单极角排序)
题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...
- poj 2007 Scrambled Polygon 极角排序
/** 极角排序输出,,, 主要atan2(y,x) 容易失精度,,用 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 retur ...
- POJ 2007 Scrambled Polygon 凸包点排序逆时针输出
题意:如题 用Graham,直接就能得到逆时针的凸包,找到原点输出就行了,赤果果的水题- 代码: /* * Author: illuz <iilluzen[at]gmail.com> * ...
- poj 2007 Scrambled Polygon
#include<stdio.h> #include<algorithm> using namespace std; #define Max 60 struct Point { ...
随机推荐
- ES6 学习3 函数
1.函数默认参数 在ES5我们给函数定义参数默认值是怎么样? function action(num) { num = num || 200 //当传入num时,num为传入的值 //当没传入参数时, ...
- [HNOI2004]打砖块(敲砖块)
题目:codevs1257.洛谷P1437 题目大意:有一些砖块呈倒三角形状,每块砖敲掉后有一个分数.除第一行外,敲掉一块砖必须先把上面两块砖敲掉.现在你能敲m块砖,求能得到的最大分数. 解题思路:此 ...
- rdesktop 脚本
[root@Eren liwm]# cat rdesktop.sh #!/bin/bash -rdesktop -u user 192.168.122.10 -r sound:local -g 10 ...
- angular.js和vue.js中实现函数去抖(debounce)
问题描述 搜索输入框中,只当用户停止输入后,才进行后续的操作,比如发起Http请求等. 学过电子电路的同学应该知道按键防抖.原理是一样的:就是说当调用动作n毫秒后,才会执行该动作,若在这n毫秒内又调用 ...
- 普通码农和CTO之间的差距
虚心 学习的第一步是--"我不懂".一个空是水杯才能装水,如果是满的就没有办法装水了."自我肯定"是一种非常难克服的习惯,经常会有朋友看到某个技术或者实现之后不 ...
- Android端通过HttpURLConnection上传文件到server
Android端通过HttpURLConnection上传文件到server 一:实现原理 近期在做Androidclient的应用开发,涉及到要把图片上传到后台server中.自己选择了做Sprin ...
- 《Spring技术内幕》笔记-Spring的设计理念和总体架构
1.Spring的主要子项目: -1.Spring Framework(Core):Spring项目的核心.提供IoC,AOP,MVC等核心功能. -2.Spring Web Flow ...
- hadoop-14-进行libtirpc的rpm包安装
hadoop-14-进行libtirpc的rpm包安装 安装过程中出现了这个问题,进行安装: yum localinstall --nogpgcheck libtirpc-0.2.1-13.el6.x ...
- MongoDB学习笔记<七>
继续MongoDB的学习 1.导出数据(中断其它操作) 把数据库test中的books集合导出 在终端下进行操作 mongoexport -d test -c books -o /home/hadoo ...
- 第十六周项目3:max带来的冲突
问题及代码: /* *Copyright (c)2015,烟台大学计算机与控制工程学院 *All rights reserved. *文件名:project.cpp *作 者:陈文青 *完毕日期:20 ...