题目传送门

题意:求凸包 + (int)求面积 / 50

  1. /************************************************
  2. * Author :Running_Time
  3. * Created Time :2015/11/4 星期三 11:13:29
  4. * File Name :POJ_3348.cpp
  5. ************************************************/
  6.  
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <iostream>
  10. #include <sstream>
  11. #include <cstring>
  12. #include <cmath>
  13. #include <string>
  14. #include <vector>
  15. #include <queue>
  16. #include <deque>
  17. #include <stack>
  18. #include <list>
  19. #include <map>
  20. #include <set>
  21. #include <bitset>
  22. #include <cstdlib>
  23. #include <ctime>
  24. using namespace std;
  25.  
  26. #define lson l, mid, rt << 1
  27. #define rson mid + 1, r, rt << 1 | 1
  28. typedef long long ll;
  29. const int N = 1e5 + 10;
  30. const int INF = 0x3f3f3f3f;
  31. const int MOD = 1e9 + 7;
  32. const double EPS = 1e-10;
  33. const double PI = acos (-1.0);
  34. int dcmp(double x) {
  35. if (fabs (x) < EPS) return 0;
  36. else return x < 0 ? -1 : 1;
  37. }
  38. struct Point {
  39. double x, y;
  40. Point () {}
  41. Point (double x, double y) : x (x), y (y) {}
  42. Point operator - (const Point &r) const {
  43. return Point (x - r.x, y - r.y);
  44. }
  45. bool operator < (const Point &r) const {
  46. return x < r.x || (x == r.x && y < r.y);
  47. }
  48. bool operator == (const Point &r) const {
  49. return dcmp (x - r.x) == 0 && dcmp (y - r.y) == 0;
  50. }
  51. };
  52. typedef Point Vector;
  53. Point read_point(void) {
  54. double x, y; scanf ("%lf%lf", &x, &y);
  55. return Point (x, y);
  56. }
  57. double dot(Point a, Point b) {
  58. return a.x * b.x + a.y * b.y;
  59. }
  60. double cross(Vector A, Vector B) {
  61. return A.x * B.y - A.y * B.x;
  62. }
  63. bool on_seg(Point p, Point a, Point b) {
  64. return dcmp (cross (a - p, b - p)) == 0 && dcmp (dot (a - p, b - p)) < 0;
  65. }
  66. double area_poly(vector<Point> ps) {
  67. double ret = 0;
  68. for (int i=1; i<ps.size ()-1; ++i) {
  69. ret += fabs (cross (ps[i] - ps[0], ps[i+1] - ps[0])) / 2;
  70. }
  71. return ret;
  72. }
  73.  
  74. /*
  75. 凸包边上无点:<= 凸包边上有点:<
  76. */
  77. vector<Point> convex_hull(vector<Point> ps) {
  78. sort (ps.begin (), ps.end ());
  79. int n = ps.size (), k = 0;
  80. vector<Point> qs (n * 2);
  81. for (int i=0; i<n; ++i) {
  82. while (k > 1 && cross (qs[k-1] - qs[k-2], ps[i] - qs[k-1]) <= 0) k--;
  83. qs[k++] = ps[i];
  84. }
  85. for (int t=k, i=n-2; i>=0; --i) {
  86. while (k > t && cross (qs[k-1] - qs[k-2], ps[i] - qs[k-1]) <= 0) k--;
  87. qs[k++] = ps[i];
  88. }
  89. qs.resize (k - 1);
  90. return qs;
  91. }
  92. int main(void) {
  93. int n;
  94. while (scanf ("%d", &n) == 1) {
  95. vector<Point> ps;
  96. for (int i=0; i<n; ++i) ps.push_back (read_point ());
  97. vector<Point> qs = convex_hull (ps);
  98. double area = area_poly (qs);
  99. printf ("%d\n", (int) area / 50);
  100. }
  101.  
  102. //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  103.  
  104. return 0;
  105. }

  

简单几何(凸包+多边形面积) POJ 3348 Cows的更多相关文章

  1. poj3348 Cows 凸包+多边形面积 水题

    /* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...

  2. poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7038   Accepted: 3242 Description ...

  3. POJ 3348 Cows(凸包+多边形面积)

    Description Your friend to the south is interested in building fences and turning plowshares into sw ...

  4. POJ 3348 - Cows 凸包面积

    求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...

  5. POJ 3348 Cows 凸包 求面积

    LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...

  6. poj 3348:Cows(计算几何,求凸包面积)

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6199   Accepted: 2822 Description ...

  7. 简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping

    题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...

  8. POJ 3348 Cows (凸包模板+凸包面积)

    Description Your friend to the south is interested in building fences and turning plowshares into sw ...

  9. POJ 3348 /// 凸包+多边形面积

    题目大意: 给定的n个点 能圈出的最大范围中 若每50平方米放一头牛 一共能放多少头 求凸包 答案就是 凸包的面积/50 向下取整 /// 求多边形面积// 凹多边形同样适用 因为点积求出的是有向面积 ...

随机推荐

  1. Cocos2d-x 3.0修改Android平台帧率fps - 解决游戏运行手机发热发烫问题

    使用Cocos2d-x 3.0开发游戏之后,发现游戏在android手机上发热非常严重,在魅族2上,几乎担心手机会爆炸了~~~采取的一个措施就是降低帧率,因为游戏对于帧率要求不是非常高. 做过coco ...

  2. Swift Tour 随笔总结 (1)

    let Constant var Variable let implicitInteger = 70 let implicitDouble = 70.0 let explicitDouble: Dou ...

  3. JVM垃圾收集策略解析

    地址:http://developer.51cto.com/art/201002/184385_all.htm

  4. 基于2d Tool Kit 精灵合图,动作生成工具

    http://blog.csdn.net/onerain88/article/details/18563687 2d Tool Kit 是一款出色的基于unity3d 开发2d游戏的工具,提供了丰富的 ...

  5. JdbcTemplate三种常用回调方法

    JdbcTemplate针对数据查询提供了多个重载的模板方法,你可以根据需要选用不同的模板方法. 如果你的查询很简单,仅仅是传入相应SQL或者相关参数,然后取得一个单一的结果,那么你可以选择如下一组便 ...

  6. jquery取checkbox选中的值

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  7. Segment Tree Build I & II

    Segment Tree Build I The structure of Segment Tree is a binary tree which each node has two attribut ...

  8. js获取文本框输入的值

    <script type="text/javascript"> function getPosition(obj) { ; if (obj.selectionStart ...

  9. MongoDB副本集学习(二):基本测试与应用

    简单副本集测试 这一节主要对上一节搭建的副本集做一些简单的测试. 我们首先进入primary节点(37017),并向test.test集合里插入10W条数据: . rs0:PRIMARY> ;i ...

  10. 【JAVA、C++】LeetCode 015 3Sum

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...