直接求凸包,输出即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std;
const int MAXN=100;
int n,l; int st[MAXN],stop,cnt;
int ans[MAXN]; struct point{
int x,y;
}p[MAXN]; bool cmp(point A,point B){
if(A.y<B.y) return true;
else if(A.y==B.y){
if(A.x<B.x) return true;
}
return false;
} bool multi(point a,point b,point c){
return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x)<=0;
} void slove(){
stop=0; cnt=0;
st[stop++]=0; st[stop++]=1;
for(int i=2;i<n;i++){
while(stop>1&&multi(p[st[stop-1]],p[i],p[st[stop-2]])) stop--;
st[stop++]=i;
}
for(int i=0;i<stop;i++){
ans[cnt++]=st[i];
}
stop=0;
st[stop++]=n-1; st[stop++]=n-2;
for(int i=n-3;i>=0;i--){
while(stop>1&&multi(p[st[stop-1]],p[i],p[st[stop-2]])) stop--;
st[stop++]=i;
}
for(int i=1;i<stop-1;i++)
ans[cnt++]=st[i];
} int main(){
n=0;
while(scanf("%d%d",&p[n].x,&p[n].y)!=EOF) n++;
sort(p,p+n,cmp);
slove();
int i,k;
for(k=0;k<cnt;k++){
if(p[ans[k]].x==0&&p[ans[k]].y==0) break;
}
printf("(%d,%d)\n",p[ans[k]].x,p[ans[k]].y);
for(int i=k+1;i<cnt;i++){
printf("(%d,%d)\n",p[ans[i]].x,p[ans[i]].y);
}
for(int i=0;i<k;i++){
printf("(%d,%d)\n",p[ans[i]].x,p[ans[i]].y);
}
return 0;
}

  

POJ 2007的更多相关文章

  1. POJ 2007 Scrambled Polygon 极角序 水

    LINK 题意:给出一个简单多边形,按极角序输出其坐标. 思路:水题.对任意两点求叉积正负判断相对位置,为0则按长度排序 /** @Date : 2017-07-13 16:46:17 * @File ...

  2. POJ - 2007 极角排序(Java 实现)

    POJ 2007 将所有的点按逆时针输出 import java.io.*; import java.util.*; public class Main { static class Point im ...

  3. poj 2007 Scrambled Polygon(极角排序)

    http://poj.org/problem?id=2007 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6701   A ...

  4. ●POJ 2007 Scrambled Polygon

    题链: http://poj.org/problem?id=2007 题解: 计算几何,极角排序 按样例来说,应该就是要把凸包上的i点按 第三像限-第四像限-第一像限-第二像限 的顺序输出. 按 叉积 ...

  5. 简单几何(极角排序) POJ 2007 Scrambled Polygon

    题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time ...

  6. POJ 2007 Scrambled Polygon (简单极角排序)

    题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio. ...

  7. Scrambled Polygon - POJ 2007(求凸包)

    给一些点,这些点都是一个凸包上的顶点,以第一个点为起点顺时针把别的点拍排一下序列. 分析:最简单的极坐标排序了..................... 代码如下: ----------------- ...

  8. POJ 2007 Scrambled Polygon 凸包

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7214   Accepted: 3445 ...

  9. poj 2007 Scrambled Polygon 极角排序

    /** 极角排序输出,,, 主要atan2(y,x) 容易失精度,,用 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 retur ...

  10. POJ 2007 Scrambled Polygon [凸包 极角排序]

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8636   Accepted: 4105 ...

随机推荐

  1. ISLR学习笔记

    目录 C1 Introduction to Statistical Learning 1.1Statistical Learning介绍: 1.1.1 估计 \(f\) 的目的:prediction和 ...

  2. Shredding Company(dfs)

    http://poj.org/problem?id=1416 题意:将一个数分成几部分,使其分割的各个数的和最大并且小于所给的数. 凌乱了..参考的会神的代码..orz... #include < ...

  3. 动态title

    <html><head><meta charset="uft8"><title>测试title</title></ ...

  4. php导出mysql源码

    件名:db_backup.php 源代码如下: 复制代码 代码如下: <?php ini_set("max_execution_time", "180") ...

  5. # Nginx设置浏览器缓存

    配置语法 在location或if段里,来写. 格式 expires 30s; expires 30m; expires 2h; expires 30d; (注意:服务器的日期要准确,如果服务器的日期 ...

  6. spring事务回滚问题

    刚刚接到一个上家公司同事的一个电话,问我为什么service方法事务不会滚了,日志打印了,调用webservice报错. 我让他把这个调用执行webservice的方法截图发给我,如下:   publ ...

  7. Runtime的相关知识

    Runtime是近年来面试遇到的一个高频方向,也是我们平时开发中或多或少接触的一个领域,那么什么是runtime呢?它又可以用来做什么呢? 什么是Runtime?平时项目中有用过么? OC是一门动态性 ...

  8. java多线线程停止正确方法

    //军队线程 //模拟作战双方的行为 public class ArmyRunnable implements Runnable { //volatile保证了线程可以正确的读取其他线程写入的值 // ...

  9. [Intermediate Algorithm] - Steamroller

    题目 对嵌套的数组进行扁平化处理.你必须考虑到不同层级的嵌套. 提示 Array.isArray() 测试用例 steamroller([[["a"]], [["b&qu ...

  10. C# MVC 返回html内容

    var ss = Server.MapPath(""); //C:\Users\Administrator\Desktop\Csharp测试程序\TestMVC\TestMVC s ...