题目传送门

题意:求凸包 + (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的更多相关文章

  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. 避免使用CSS表达式

    http://www.cnblogs.com/chenxizhang/archive/2013/05/01/3053439.html 这一篇我来和大家讨论个原则:Avoid CSS Expressio ...

  2. 关于showModalDialog()对话框点击按钮弹出新页面的问题

    页面a.aspx上,单击按钮a,走脚本,弹出showModalDialog("b.aspx",....) 在b.aspx上有个服务器控件按钮b,单击按钮,更新数据后,会弹出一个新的 ...

  3. [Effective JavaScript笔记]第1条:了解使用的js版本

    1997年 正式成为国际标准,官方名称为ECMAScript. 1999年 定稿第3版ECMAScript标准(简称ES3),最广泛的js版本. 2009年 发布第5版即ES5,引入了一些新特性,标准 ...

  4. centos安装ssdb

    在编译之前要下gcc编译器 yum -y install gcc*   编译和安装 wget --no-check-certificate https://github.com/ideawu/ssdb ...

  5. 【Python】 Django 怎么实现 联合主键?

    unique_together¶ Options.unique_together¶ Sets of field names that, taken together, must be unique: ...

  6. 【SpringMVC】SpringMVC系列14之SpringMVC国际化

    14.SpringMVC国际化 14.1.概述 14.2.用户切换选择语言

  7. swiper组件实现向上翻页时缩小

    var mySwiper = new Swiper ('.swiper-container', { direction: 'vertical', loop: true, // 如果需要前进后退按钮 n ...

  8. Android studio 添加依赖

    以前添加依赖总是到github上下载源码,再添加源码到module的依赖当中,其实在studio中,应该使用maven库. 比如在github上看到了sliding-menu这个项目,就应该到mave ...

  9. 转数据库分库分表(sharding)系列(二) 全局主键生成策略

    本文将主要介绍一些常见的全局主键生成策略,然后重点介绍flickr使用的一种非常优秀的全局主键生成方案.关于分库分表(sharding)的拆分策略和实施细则,请参考该系列的前一篇文章:数据库分库分表( ...

  10. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...