博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3384
阅读量:7060 次
发布时间:2019-06-28

本文共 1739 字,大约阅读时间需要 5 分钟。

题意:求凸包面积/50,并取整。

分析:用模板。

View Code
#include 
#include
#include
#include
#include
using namespace std;#define maxn 10005struct Point{ double x, y;} point[maxn], cvx[maxn];int n, m;bool mult(Point sp, Point ep, Point op){ return (sp.x - ep.x) * (ep.y - op.y) >= (ep.x - op.x) * (sp.y - ep.y);}bool operator <(const Point &l, const Point &r){ return l.y < r.y || (l.y == r.y && l.x < r.x);}int graham(Point pnt[], int n, Point res[]){ int i, len, top = 1; sort(pnt, pnt + n); if (n == 0) return 0; res[0] = pnt[0]; if (n == 1) return 1; res[1] = pnt[1]; if (n == 2) return 2; res[2] = pnt[2]; for (i = 2; i < n; i++) { while (top && mult(pnt[i], res[top], res[top - 1])) top--; res[++top] = pnt[i]; } len = top; res[++top] = pnt[n - 2]; for (i = n - 3; i >= 0; i--) { while (top != len && mult(pnt[i], res[top], res[top - 1])) top--; res[++top] = pnt[i]; } return top; // 返回凸包中点的个数}void input(){ scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lf %lf", &point[i].x, &point[i].y);}double areaofp(int vcount, Point plg[]){ int i; double s; if (vcount < 3) return 0; s = plg[0].y * (plg[vcount - 1].x - plg[1].x); for (i = 1; i < vcount; i++) s += plg[i].y * (plg[(i - 1)].x - plg[(i + 1) % vcount].x); return s / 2;}int main(){ //freopen("t.txt", "r", stdin); input(); m = graham(point, n, cvx); printf("%d\n", (int)(areaofp(m, cvx) / 50)); return 0;}

转载于:https://www.cnblogs.com/rainydays/archive/2012/07/03/2575244.html

你可能感兴趣的文章
[摘录]高效人士七习惯—以终为始原则
查看>>
angular 当使用ng-repeat 时出现 $$hashKey的键值对
查看>>
GoldenGate 性能优化方法
查看>>
正则表达式和re模块
查看>>
[区块链]Merkle Tree
查看>>
Token 认证
查看>>
搜索服务solr 一二事(1) - solr-5.5 使用自带Jetty或者tomcat 搭建单机版搜索服务器...
查看>>
Html5新增加的属性
查看>>
php生成图片缩略图,支持png透明
查看>>
Django——模板层(template)(模板语法、自定义模板过滤器及标签、模板继承)
查看>>
论一个蒟蒻的脑子里可以有多少坑(貌似咕了……目前更新保持在noip阶段)
查看>>
Python第三方库安装和卸载zz
查看>>
C++——虚函数表解析
查看>>
重磅!共享单车漏洞独家发布。
查看>>
html中特殊符号
查看>>
为什么 SharedPreferences 可以直接 调用,前面却没有对象
查看>>
php fsockopen 中多线程的解决办法
查看>>
yii框架后台过滤器的使用 安全防护
查看>>
[nginx]lua操作redis
查看>>
第四章 串和数组 (主要kmp算法)
查看>>