简单几何(凸包+多边形面积) 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;
}

  

时间: 2024-12-15 04:46:55

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

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

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7038   Accepted: 3242 Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are f

POJ 3348 Cows 凸包 求面积

LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileName: POJ 3348 凸包面积 叉积.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.com/ * @Version : $Id$ */ #include <std

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

题目传送门 题意:告诉若干个矩形的信息,问他们在凸多边形中所占的面积比例 分析:训练指南P272,矩形面积长*宽,只要计算出所有的点,用凸包后再求多边形面积.已知矩形的中心,向量在原点参考点再旋转,角度要转换成弧度制. /************************************************ * Author :Running_Time * Created Time :2015/11/10 星期二 10:34:43 * File Name :UVA_10652.cpp

poj 3348 Cows 求凸包面积

题目链接 大意: 求凸包的面积. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <queue>

简单几何(凸包) POJ 1113 Wall

题目传送门 题意:求最短路线,使得线上任意一点离城堡至少L距离 分析:先求凸包,答案 = 凸包的长度 + 以L为半径的圆的周长 /************************************************ * Author :Running_Time * Created Time :2015/10/25 11:00:48 * File Name :POJ_1113.cpp ************************************************/ #

●POJ 3348 Cows

题链: http://poj.org/problem?id=3348 题解: 计算几何,凸包,多边形面积 好吧,就是个裸题,没什么可讲的. 代码: #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define MAXN 10050 using namespace std; const double eps=1e-8

POJ 3348 Cows

简单的求凸多边形面积 求不规则多边形也是类似 只要选择的点是沿着多边形边选就行了  通过容斥会得到正确答案 #include<cmath> #include<cstdio> #include<algorithm> #define db double using namespace std; const int N=1e4+50; const db eps=1e-9; struct Point { db x,y;Point(){} Point(db _x,db _y) {

简单几何(线段相交)+模拟 POJ 3449 Geometric Shapes

题目传送门 题意:给了若干个图形,问每个图形与哪些图形相交 分析:题目说白了就是处理出每个图形的线段,然后判断是否相交.但是读入输出巨恶心,就是个模拟题加上线段相交的判断,我第一次WA不知道输出要按字母序输出,第二次WA是因为忘记多边形的最后一条线段,还好找到了,没有坚持的话就不会AC了. /************************************************ * Author :Running_Time * Created Time :2015/10/31 星期六

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

先求出凸包,然后利用凸包求出面积,除以50就是答案 代码: #include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int MAXN=10005; struct Point { double x, y; Point() {} Point(double x, double y) { this->x = x; this->y = y; } void read(