简单几何(凸包+多边形面积) POJ 3348 Cows
题意:求凸包 + (int)求面积 / 50
- /************************************************
- * Author :Running_Time
- * Created Time :2015/11/4 星期三 11:13:29
- * File Name :POJ_3348.cpp
- ************************************************/
- #include <cstdio>
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <cstring>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <list>
- #include <map>
- #include <set>
- #include <bitset>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- #define lson l, mid, rt << 1
- #define rson mid + 1, r, rt << 1 | 1
- typedef long long ll;
- const int N = 1e5 + 10;
- const int INF = 0x3f3f3f3f;
- const int MOD = 1e9 + 7;
- const double EPS = 1e-10;
- const double PI = acos (-1.0);
- int dcmp(double x) {
- if (fabs (x) < EPS) return 0;
- else return x < 0 ? -1 : 1;
- }
- struct Point {
- double x, y;
- Point () {}
- Point (double x, double y) : x (x), y (y) {}
- Point operator - (const Point &r) const {
- return Point (x - r.x, y - r.y);
- }
- bool operator < (const Point &r) const {
- return x < r.x || (x == r.x && y < r.y);
- }
- bool operator == (const Point &r) const {
- return dcmp (x - r.x) == 0 && dcmp (y - r.y) == 0;
- }
- };
- typedef Point Vector;
- Point read_point(void) {
- double x, y; scanf ("%lf%lf", &x, &y);
- return Point (x, y);
- }
- double dot(Point a, Point b) {
- return a.x * b.x + a.y * b.y;
- }
- double cross(Vector A, Vector B) {
- return A.x * B.y - A.y * B.x;
- }
- bool on_seg(Point p, Point a, Point b) {
- return dcmp (cross (a - p, b - p)) == 0 && dcmp (dot (a - p, b - p)) < 0;
- }
- double area_poly(vector<Point> ps) {
- double ret = 0;
- for (int i=1; i<ps.size ()-1; ++i) {
- ret += fabs (cross (ps[i] - ps[0], ps[i+1] - ps[0])) / 2;
- }
- return ret;
- }
- /*
- 凸包边上无点:<= 凸包边上有点:<
- */
- vector<Point> convex_hull(vector<Point> ps) {
- sort (ps.begin (), ps.end ());
- int n = ps.size (), k = 0;
- vector<Point> qs (n * 2);
- for (int i=0; i<n; ++i) {
- while (k > 1 && cross (qs[k-1] - qs[k-2], ps[i] - qs[k-1]) <= 0) k--;
- qs[k++] = ps[i];
- }
- for (int t=k, i=n-2; i>=0; --i) {
- while (k > t && cross (qs[k-1] - qs[k-2], ps[i] - qs[k-1]) <= 0) k--;
- qs[k++] = ps[i];
- }
- qs.resize (k - 1);
- return qs;
- }
- int main(void) {
- int n;
- while (scanf ("%d", &n) == 1) {
- vector<Point> ps;
- for (int i=0; i<n; ++i) ps.push_back (read_point ());
- vector<Point> qs = convex_hull (ps);
- double area = area_poly (qs);
- printf ("%d\n", (int) area / 50);
- }
- //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
- return 0;
- }
简单几何(凸包+多边形面积) POJ 3348 Cows的更多相关文章
- poj3348 Cows 凸包+多边形面积 水题
/* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- POJ 3348 Cows(凸包+多边形面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
- POJ 3348 - Cows 凸包面积
求凸包面积.求结果后不用加绝对值,这是BBS()排序决定的. //Ps 熟练了template <class T>之后用起来真心方便= = //POJ 3348 //凸包面积 //1A 2 ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- poj 3348:Cows(计算几何,求凸包面积)
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6199 Accepted: 2822 Description ...
- 简单几何(向量旋转+凸包+多边形面积) UVA 10652 Board Wrapping
题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角 ...
- POJ 3348 Cows (凸包模板+凸包面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
- POJ 3348 /// 凸包+多边形面积
题目大意: 给定的n个点 能圈出的最大范围中 若每50平方米放一头牛 一共能放多少头 求凸包 答案就是 凸包的面积/50 向下取整 /// 求多边形面积// 凹多边形同样适用 因为点积求出的是有向面积 ...
随机推荐
- Cocos2d-x 3.0修改Android平台帧率fps - 解决游戏运行手机发热发烫问题
使用Cocos2d-x 3.0开发游戏之后,发现游戏在android手机上发热非常严重,在魅族2上,几乎担心手机会爆炸了~~~采取的一个措施就是降低帧率,因为游戏对于帧率要求不是非常高. 做过coco ...
- Swift Tour 随笔总结 (1)
let Constant var Variable let implicitInteger = 70 let implicitDouble = 70.0 let explicitDouble: Dou ...
- JVM垃圾收集策略解析
地址:http://developer.51cto.com/art/201002/184385_all.htm
- 基于2d Tool Kit 精灵合图,动作生成工具
http://blog.csdn.net/onerain88/article/details/18563687 2d Tool Kit 是一款出色的基于unity3d 开发2d游戏的工具,提供了丰富的 ...
- JdbcTemplate三种常用回调方法
JdbcTemplate针对数据查询提供了多个重载的模板方法,你可以根据需要选用不同的模板方法. 如果你的查询很简单,仅仅是传入相应SQL或者相关参数,然后取得一个单一的结果,那么你可以选择如下一组便 ...
- jquery取checkbox选中的值
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- Segment Tree Build I & II
Segment Tree Build I The structure of Segment Tree is a binary tree which each node has two attribut ...
- js获取文本框输入的值
<script type="text/javascript"> function getPosition(obj) { ; if (obj.selectionStart ...
- MongoDB副本集学习(二):基本测试与应用
简单副本集测试 这一节主要对上一节搭建的副本集做一些简单的测试. 我们首先进入primary节点(37017),并向test.test集合里插入10W条数据: . rs0:PRIMARY> ;i ...
- 【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 ...