poj 2007 Scrambled Polygon [极角排序]
来源:互联网 发布:windows资源管理器视图 编辑:程序博客网 时间:2024/05/21 10:08
题目链接:点击打开链接
题目的意思很简单,就是从(0,0)开始,依次逆时针输出凸包的顶点。(没有任意三点在一条直线上,并且所有的点都只在三个象限中)。
我直接按照求凸包时候的方法来进行排序的,找到(0,0)点,然后逆时针输出。
所有的点都只能再斜率为1的两条线的一侧。
Code:
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int N = 55;struct POINT{ double x, y;}p[N];double cross(POINT o, POINT a, POINT b){ return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);}bool cmp(POINT a, POINT b){ if(a.y < b.y || (a.y == b.y && a.x < b.x)) return true; else return false;}bool cmp1(POINT a, POINT b){ if(cross(p[0], a, b) > 0) return true; else return false;}int main(){ int n = 0; while(~scanf("%lf %lf", &p[n].x, &p[n].y)){ n ++; } int ca = n, i; sort(p, p + n, cmp); sort(p + 1, p + n, cmp1); for(i = 0; i < n; i ++){ if(p[i].x == 0 && p[i].y == 0) break; } while(ca --){ printf("(%.0lf,%.0lf)\n", p[i % n].x, p[i % n].y); i = (i + 1) % n; } return 0;}
G++提交了好多次,都是wa。最后的结论是,G++ 对于double的输入要%lf,而对于输出要%f。我擦,第一次听说这个,好吧,长见识了。
但对于C++ 不管是输入还是输出都是%lf。
0 0
- 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 2007 Scrambled Polygon(极角排序)
- POJ 2007 Scrambled Polygon (极角排序)
- poj 2007 Scrambled Polygon(极角排序)
- POJ 2007 Scrambled Polygon(点的极角排序)
- POJ 2007 Scrambled Polygon(简单极角排序)
- POJ 2007:Scrambled Polygon (极角排序)
- POJ 2007 Scrambled Polygon (极角排序+叉乘)
- HDU-2007 Scrambled Polygon 极角排序
- PKU 2007 Scrambled Polygon 极角排序
- poj 2007 Scrambled Polygon--按极角排序
- 计算几何:极角排序(poj 2007 Scrambled Polygon)与简单凸包(poj 1113 Wall)
- poj 2007 Scrambled Polygon
- HDOJ 2003 求绝对值
- 内存耗用:VSS/RSS/PSS/USS
- ASP.NET弹出提示框不同方式
- SpringMVC+IBatis之IBatis配置
- iOS7.1企业级证书 http服务访问无效 解决
- poj 2007 Scrambled Polygon [极角排序]
- SQL Server 分页
- 运用JS设置cookie、读取cookie、删除cookie
- 中科燕园GIS外包 讲解2---使用geoserver+openLayers加载google地图
- WPF 附加属性
- 基于注解的SpringMVC+freemarker环境搭建
- HDU 3397 Sequence operation (线段树,成段更新,区间合并)
- 编辑距离算法
- 2014.7.21