题目链接:https://cn.vjudge.net/problem/POJ-3348

题意

啊模版题啊

求凸包的面积,除50即可

思路

求凸包的面积,除50即可

提交过程

AC

代码

#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const double eps=1e-10;
struct Point{
double x, y; Point(int x=0, int y=0):x(x), y(y) {}
// no known conversion for argument 1 from 'Point' to 'Point&'
Point operator + (Point p){return Point(x+p.x, y+p.y);}
Point operator - (Point p){return Point(x-p.x, y-p.y);}
Point operator * (double k){return Point(k*x, k*y);}
Point operator / (double k){return Point(x/k, y/k);}
bool operator < (Point p) const{return (x==p.x)?(y<p.y):(x<p.x);} // need eps?
bool operator == (const Point p) const{return fabs(x-p.x)<eps&&fabs(y-p.y)<eps;}
double norm(void){return x*x+y*y;}
double abs(void){return sqrt(norm());}
double dot(Point p){return x*p.x+y*p.y;} // cos
double cross(Point p){return x*p.y-y*p.x;} // sin
};
struct Segment{Point p1, p2;};
struct Circle{Point o; double rad;};
typedef Point Vector;
typedef vector<Point> Polygon;
typedef Segment Line; int ccw(Point p0, Point p1, Point p2){
Vector v1=p1-p0, v2=p2-p0;
if (v1.cross(v2)>eps) return 1; // anti-clockwise
if (v1.cross(v2)<-eps) return -1; // clockwise
if (v1.dot(v2)<0) return 2;
if (v1.norm()<v2.norm()) return -2;
return 0;
} Point project(Segment s, Point p){
Vector base=s.p2-s.p1;
double k=(p-s.p1).cross(base)/base.norm();
return s.p1+base*k;
} Point reflect(Segment s, Point &p){
return p+(project(s, p)-p)*2;
} double lineDist(Line l, Point p){
return abs((l.p2-l.p1).cross(p-l.p1)/(l.p2-l.p1).abs());
} double SegDist(Segment s, Point p){
if ((s.p2-s.p1).dot(p-s.p1)<0) return Point(p-s.p1).abs();
if ((s.p1-s.p2).dot(p-s.p2)<0) return Point(p-s.p2).abs();
return abs((s.p2-s.p1).cross(p-s.p1)/(s.p2-s.p1).abs());
} bool intersect(Point p1, Point p2, Point p3, Point p4){
return ccw(p1, p2, p3)*ccw(p1, p2, p4)<=0 &&
ccw(p3, p4, p1)*ccw(p3, p4, p2)<=0;
} Point getCrossPoint(Segment s1, Segment s2){
Vector base=s2.p2-s2.p1;
double d1=abs(base.cross(s1.p1-s2.p1));
double d2=abs(base.cross(s1.p2-s2.p1));
double t=d1/(d1+d2);
return s1.p1+(s1.p2-s1.p1)*t;
} double area(Polygon poly){
double res=0; long long size=poly.size();
for (int i=0; i<poly.size(); i++)
res+=poly[i].cross(poly[(i+1)%size]);
return abs(res/2);
} int contain(Polygon poly, Point p){
int n=poly.size();
bool flg=false;
for (int i=0; i<n; i++){
Point a=poly[i]-p, b=poly[(i+1)%n]-p;
if (ccw(poly[i], poly[(i+1)%n], p)==0) return 1; // 1 means on the polygon.
if (a.y>b.y) swap(a, b);
if (a.y<0 && b.y>0 && a.cross(b)>0) flg=!flg;
}return flg?2:0; // 2 fo inner, 0 for outer.
} Polygon convexHull(Polygon poly){
if (poly.size()<3) return poly;
Polygon upper, lower;
sort(poly.begin(), poly.end());
upper.push_back(poly[0]); upper.push_back(poly[1]);
lower.push_back(poly[poly.size()-1]); lower.push_back(poly[poly.size()-2]);
for (int i=2; i<poly.size(); i++){
for (int n=upper.size()-1; n>=1 && ccw(upper[n-1], upper[n], poly[i])!=-1; n--)
upper.pop_back();
upper.push_back(poly[i]);
}
for (int i=poly.size()-3; i>=0; i--){
for (int n=lower.size()-1; n>=1 && ccw(lower[n-1], lower[n], poly[i])!=-1; n--)
lower.pop_back();
lower.push_back(poly[i]);
}
for (int i=1; i<lower.size(); i++)
upper.push_back(lower[i]);
return upper;
} int main(void){
int n;
double x, y; while (scanf("%d", &n)==1 && n){
Polygon poly, hull;
for (int i=0; i<n; i++){
scanf("%lf%lf", &x, &y);
poly.push_back(Point(x, y));
}
printf("%d\n", (long long)area(convexHull(poly))/50);
} return 0;
}
Time Memory Length Lang Submitted
608kB 3526 G++ 2018-08-01 17:22:02

POJ-3348 Cows 计算几何 求凸包 求多边形面积的更多相关文章

  1. ●POJ 3348 Cows

    题链: http://poj.org/problem?id=3348 题解: 计算几何,凸包,多边形面积 好吧,就是个裸题,没什么可讲的. 代码: #include<cmath> #inc ...

  2. UVa 10652(旋转、凸包、多边形面积)

    要点 凸包显然 长方形旋转较好的处理方式就是用中点的Vector加上旋转的Vector,然后每个点都扔到凸包里 多边形面积板子求凸包面积即可 #include <cstdio> #incl ...

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

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

  4. POJ 3348 Cows 凸包 求面积

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

  5. poj 3348 Cows 求凸包面积

    题目链接 大意: 求凸包的面积. #include <iostream> #include <vector> #include <cstdio> #include ...

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

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

  7. 简单几何(凸包+多边形面积) POJ 3348 Cows

    题目传送门 题意:求凸包 + (int)求面积 / 50 /************************************************ * Author :Running_Tim ...

  8. POJ 3348 - Cows 凸包面积

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

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

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

随机推荐

  1. [spoj] HIGH - Highways (生成树计数)

    传送门 输入格式: 第一行一个整数T,表示测试数据的个数 每个测试数据第一行给出 n,m 分别表示点数与边数 接下来 m 行,每行给出两个数 a,b ,表示 a,b 之间有一条无向边 输出格式: 每个 ...

  2. 使用python备份指定目录并删除备份超过一定时长的文件

    #!/usr/bin/env python #-*- coding: utf-8 -*- """ @Project:Py @author: @Email: @Softwa ...

  3. ubuntu 12.04下安装Qt出现cannot execute binary file的解决方案

    最近在ubuntu 12.04下安装QT的过程中,遇到一个问题. ./qt-opensource-linux-x64-5.7.0.run出现了bash: ./qt-opensource-linux-x ...

  4. linux下的查找命令

    whereis <程序名称> 查找软件的安装路径 -b 只查找二进制文件 -m 只查找帮助文件 -s 只查找源代码 -u 排除指定类型文件 -f 只显示文件名 -B <目录> ...

  5. JS数据分组[JSON]

    JS 数据分组 var arr = [{ "id": "1001", "name": "值1", "value ...

  6. multiple definition of

    总结了解决multiple definition of的方法: 问题原因:    当多个文件包含同一个头文件时,并且你的.H里面没有加上条件编译#ifndef TEST_H#define TEST_H ...

  7. STM32 IIC双机通信—— HAL库硬件IIC版

    参考传送门 关于IIC的原理这里我就不多说了,网上有很多很好的解析,如果要看我个人对IIC的理解的话,可以点击查看,这里主要讲一下怎样利用STM32CubeMx实现IIC的通讯,经过个人实践,感觉HA ...

  8. ASP.NET-Router配置中MapRoute的参数

    App_Start文件夹中的RouteConfig MapRoute(string name,string url); MapRoute(string name,string url,object d ...

  9. 洛谷—— P1640 [SCOI2010]连续攻击游戏

    https://www.luogu.org/problem/show?pid=1640 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1, ...

  10. 【中山市选2010】【BZOJ2467】生成树

    Description 有一种图形叫做五角形圈.一个五角形圈的中心有1个由n个顶点和n条边组成的圈. 在中心的这个n边圈的每一条边同一时候也是某一个五角形的一条边,一共同拥有n个不同的五角形.这些五角 ...