凸包模版和博客
来源:互联网 发布:维多利亚大学 知乎 编辑:程序博客网 时间:2024/06/05 09:15
http://blog.csdn.net/nyist_tc_lyq/article/details/74776760
http://blog.csdn.net/bone_ace/article/details/46239187
http://www.cnblogs.com/Booble/archive/2011/02/28/1967179.html
#include<bits/stdc++.h>using namespace std;struct Z{ double x,y;} z[1000],p[1000];//距离double dis(Z a,Z b){ double d=(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); return d;}//叉积double mm(Z a,Z b,Z c){ return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);}//级角排序int cmp(Z a,Z b){ double x=mm(a,b,z[0]); if(x>0||(x==0&&dis(a,z[0])<dis(b,z[0]))) return 1; return 0;}//输出排序int cmpp(Z a,Z b){ if(a.x!=b.x) return a.x<b.x; else return a.y<b.y;}int main(){ int t; cin>>t; while(t--) { int m; cin>>m; int w=m; while(w--) { cin>>z[w].x>>z[w].y; }//Graham扫描法 int k=0; for(int i=0; i<m; i++) { if(z[i].y<z[k].y||(z[i].y==z[k].y&&z[i].x<z[k].x))k=i; } swap(z[0],z[k]); sort(z+1,z+m,cmp); int top=2; p[0]=z[0]; p[1]=z[1]; for(int i=2; i<m; i++) { while(top>1&&mm(p[top-1],p[top-2],z[i])>=0) { top--; } p[top++]=z[i]; }//输出要求 sort(p,p+top,cmpp); cout<<top<<endl; for(int i=0; i<top; i++) { cout<<p[i].x<<" "<<p[i].y<<endl;; } }}
阅读全文
0 0
- 凸包模版和博客
- 凸包和旋转卡壳 模版
- 二维凸包模版
- 凸包模版
- 凸包模版
- HDOJ1348凸包模版
- HDOJ1392凸包模版
- 函数模版之凸包
- Surround Threes (凸包模版)
- 博客模版
- 三维凸包模版 求三维凸包的表面积和体积
- poj 3348(凸包模版体)
- HDU/HDOJ2202凸包模版+枚举
- POJ 1113 凸包模版题
- HDOJ_1392 Surround The Trees (凸包模版)
- 凸包模版 HDU1392 Surround the Trees
- POJ 1113凸包模版题 (自己的凸包模版)
- 本人的博客模版
- Java
- 使用装饰设计模式加密数据
- 字符串替换空格
- Java-多线程
- Jenkins Master/Slave架构
- 凸包模版和博客
- Oracle笔试题
- GDB调试
- ServerSocket简单例题
- 学习ubuntu--常用命令(二)autoremove, remove, clean
- 关于大数据学习第一天的几点认识
- Vim技能修炼教程(14)
- Android 定点显示逐帧动画,同时播放背景音乐
- 使用mvc:annotation-driven时遇到的No bean named 'cacheManager' is defined问题