开始学习计算几何啦
2016-08-05 18:42
375 查看
先预习了计算几何的基本知识,今天就要正式开始学习计算几何了。
先刷了道水题。
nyoj78 圈水池
一看就是个凸包,上网搜了凸包的资料,算是看懂了(不过写题就不会了)。
AC代码:
先刷了道水题。
nyoj78 圈水池
一看就是个凸包,上网搜了凸包的资料,算是看懂了(不过写题就不会了)。
AC代码:
#include <bits/stdc++.h> #define ll long long using namespace std; const double eps = 1e-6; struct Point{ double x,y; Point(double x=0,double y=0):x(x),y(y){} }; Point p[150],s[150]; //int dcmp(double x) { // if(fabs(x)<eps) return 0; // else return x<0 ? -1 : 1; //} double dis(Point a,Point b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double cross(Point a,Point b,Point c) { return (b.x-a.x)*(c.y - a.y) - (c.x-a.x)*(b.y-a.y); } bool cmp1(Point a,Point b) { int m = cross(p[1],a,b); if(m==0) return dis(p[1],a)-dis(p[1],b) <=0 ? true:false; else return m >0 ? true : false ; } bool cmp(const Point &a,const Point &b) { if(a.x != b.x) return a.x < b.x; else return a.y<b.y; } int main(){ // freopen("1.in","r",stdin); int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lf%lf",&p[i].x,&p[i].y); } sort(p+1,p+n+1,cmp); sort(p+2,p+n+1,cmp1); int top=1; s[0].x = p[1].x; s[0].y = p[1].y; s[1].x = p[2].x; s[1].y=p[2].y; for(int i=3;i<=n;i++) { while(i>=1 && cross(s[top-1],s[top],p[i])<0) top--; s[++top] = p[i]; } // cout<<top<<endl; sort(s,s+top+1,cmp); for(int i=0;i<=top;i++) { cout<<s[i].x<<" "<<s[i].y<<endl; } } return 0; }
相关文章推荐
- Ural 2036. Intersect Until You're Sick of It 计算几何
- uva11992 Fast Matrix Operations
- 音频重采样的基本(我的学习笔记)
- Linux查看进程所使用资源限制
- Comparator 排序
- 图片上传2
- JVM 关闭前执行命令的钩子
- Base64.java 工具类
- HDU2188(巴什博奕)
- 利用贝叶斯分类器进行文本挖掘---笔记
- Serializable 剔除某些不想保存的字段 transient
- Serializable 序列化使用限制
- Serializable 序列化为字符串 base64
- 统计连续签到的方法
- Serializable 序列化为文件
- 扩展欧几里得算法模板(希望永远不要搞懂了)
- http://www.open-open.com/lib/view/open1397274257325.html
- Spring Shedule Task之注解实现 (两次启动Schedule Task 的解决方案)
- 一把刀系统维护工具箱 v1.6 绿色版
- CSS-相對于父元素絕對定位