●POJ 2007 Scrambled Polygon
题链:
http://poj.org/problem?id=2007
题解:
计算几何,极角排序
按样例来说,应该就是要把凸包上的i点按 第三像限-第四像限-第一像限-第二像限 的顺序输出。
按 叉积 来排序的确可以A掉,但是显然有错呀。
比如这个例子:
0 0
-2 2
-1 -1
1 0
正确答案显然应该是:
(0,0)
(-2,2)
(-1,-1)
(1,0)
但是 用叉积 排序后却是这样:
(0,0)
(1,0)
(-2,2)
(-1,-1)
(要用叉积排序的话,按道理来讲应该把像限分成两块分别排序吧(上一块(1,2像限),下一块(3,4像限))。)
而用atan2函数来比较,就可以达到正确答案的效果,可是无奈在POJ上会WA,原因不明~
(疑惑疑惑疑惑疑惑疑惑疑惑疑惑,(莫不是我题读错了?))
代码:
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const double eps=1e-8;
int sign(double x){
if(fabs(x)<=eps) return 0;
return x<0?-1:1;
}
struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){}
int Read(){return scanf("%lf%lf",&x,&y);}
}D[70];
int N;
typedef Point Vector;
double operator ^ (Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double Angle(Vector A){
return atan2(A.y,A.x);
}
bool PAcmp(Point A,Point B){//Polar_Angle_cmp
//return sign(Angle(A)-Angle(B))<0;
return sign(A^B)>0;
}
void Bubble_Sort(int l,int r){
for(int i=l;i<=r;i++)
for(int j=l;j<i;j++)
if(PAcmp(D[i],D[j])) swap(D[i],D[j]);
}
int main(){
freopen("/home/noilinux/Documents/模块学习/计算几何/input","r",stdin);
while(~D[++N].Read());
sort(D+2,D+N,PAcmp);
//Bubble_Sort(2,N-1);
for(int i=1;i<N;i++)
printf("(%0.lf,%0.lf)\n",D[i].x,D[i].y);
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
题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * 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 { ...
随机推荐
- 敏捷冲刺每日报告--day2
1 团队介绍 团队组成: PM:齐爽爽(258) 小组成员:马帅(248),何健(267),蔡凯峰(285) Git链接:https://github.com/WHUSE2017/C-team ...
- mobiscroll2.5.4 日期组件
<script type="text/javascript"> function setCss(o) { $('input:jqmData(role="dat ...
- Python 实现双端队列 Deque
操作 Deque() 创建一个空的双端队列 add_front(item) 从队头加入一个item元素 add_rear(item) 从队尾加入一个item元素 remove_front() 从队头删 ...
- nyoj 还是回文
还是回文 时间限制:2000 ms | 内存限制:65535 KB 难度:3 描述 判断回文串很简单,把字符串变成回文串也不难.现在我们增加点难度,给出一串字符(全部是小写字母),添加或删除一个字符, ...
- VS Code 常用命令记录
1. 创建解决方案 例:dotnet new sln -o HelloWorld.Solutions 其中 -o 表示输出文件夹 2.创建类库.web.mvc.webapi等项目 例:dotnet n ...
- 构建微服务开发环境7————使用Github管理项目代码的版本
[内容指引] 1.注册GitHub帐号: 2.下载Github Desktop客户端: 3.macOS安装Github Desktop客户端: 4.windows安装Github Desktop客户端 ...
- JAVA_SE基础——6.标识符&关键字
学会写helloworld之后, 我们就开始来认识标识符&关键字 一.标识符 标识符是指可被用来为类.变量或方法等命名的字符序列,换言之,标识符就是用户自定义的名称来标识类.变量或方法等.更 ...
- vue jsx 使用指南
vue jsx 使用指南 vue jsx 语法与 react jsx 还是有些不一样,在这里记录下. let component = null // if 语句 if (true) { compone ...
- WPF自定义控件与样式-自定义按钮(Button)
一.前言 程序界面上的按钮多种多样,常用的就这几种:普通按钮.图标按钮.文字按钮.图片文字混合按钮.本文章记录了不同样式类型的按钮实现方法. 二.固定样式的按钮 固定样式的按钮一般在临时使用时或程序的 ...
- 修改了SpringBoot的主类名称后,gradle build报错的解决办法
Unable to find a single main class from the following candidates [*.*Application]