题目:

给几个点,用绳子圈出最大的面积养牛,输出最大面积/50


题解:

Graham凸包算法的模板题

下面给出做法

1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上)

2.其他点进行极角排序<极角指从坐标轴的某一方向逆时针旋转到向量的角度>,

 极角一样按距离从近到远(可以用叉积实现)

3.用栈维护凸包上的点,将极点和极角序最小的点依次入栈

4.按顺序扫描,检查栈顶的前两个元素与这个点构成的线段是否拐向右(顺时针侧,叉积小于0)

 如果满足就弹出栈顶元素,直到不满足或者栈里不足两个元素

 反之入栈

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
#define N 10005
using namespace std;
int n,m;
struct point
{
int x,y;
point (){};
point (int _x,int _y)
{
x=_x,y=_y;
}
point operator - (const point &a)const
{
return point (x-a.x,y-a.y);
}
int operator * (const point &a) const
{
return x*a.y-y*a.x;
}
int norm()const
{
return x*x+y*y;
}
}p[N],q[N];
bool cmp(int u,int v)
{
int det=(p[u]-p[1])*(p[v]-p[1]);
if (det!=0) return det>0;
return (p[u]-p[1]).norm() < (p[v]-p[1]).norm();
}
void Graham()
{
int id=1;
for (int i=2;i<=n;i++)
if (p[i].x<p[id].x || (p[i].x==p[id].x && p[i].y<p[id].y))
id=i;
if (id!=1) swap(p[1],p[id]);
int per[N];
for (int i=1;i<=n;i++)
per[i]=i;
sort(per+2,per+1+n,cmp);
q[++m]=p[1];
for (int i=2;i<=n;i++)
{
int j=per[i];
while (m>=2 && (p[j]-q[m-1])*(q[m]-q[m-1])>=0) m--;
q[++m]=p[j];
}
}
int Area()
{
int res=0;
q[m+1]=q[1];
for (int i=1;i<=m;i++)
res+=q[i]*q[i+1];
return res/2;
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
Graham();
int ans=Area()/50;
printf("%d\n",ans);
return 0;
}

POJ 3348 Cows | 凸包模板题的更多相关文章

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

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

  2. POJ 3348 - Cows 凸包面积

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

  3. POJ 3348 Cows [凸包 面积]

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9022   Accepted: 3992 Description ...

  4. POJ 3348 Cows 凸包 求面积

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

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

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

  6. POJ 3348 Cows | 凸包——童年的回忆(误)

    想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...

  7. poj 3348 Cow 凸包面积

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 Description ...

  8. Sliding Window POJ - 2823 单调队列模板题

    Sliding Window POJ - 2823 单调队列模板题 题意 给出一个数列 并且给出一个数m 问每个连续的m中的最小\最大值是多少,并输出 思路 使用单调队列来写,拿最小值来举例 要求区间 ...

  9. POJ 2186:Popular Cows Tarjan模板题

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25945   Accepted: 10612 De ...

随机推荐

  1. JS笔试汇总

    //console.log(a[b]); var a={}; var b={key:'b'}; var c={key:'c'}; a[b] = 456; a[c] = 123; console.log ...

  2. 本地预览的vue项目,在githubpage静态展示

    本地项目github静态展示 前提 在本地npm run dev后能够在本地端口正常显示 githubpage为自己的静态页面 上线 config/index.js中设置assetsPublicPat ...

  3. linux基础目录

    第1章 linux目录结构 1.1 linux目录结构的特点 一切皆文件 1)倒挂的树状结构   一切从根开始 2)linux每个目录可以挂载在不同的设备(磁盘)上.windows不容易做到. /da ...

  4. php学习【2】

    1:运算符 <?php $x=1; echo 1+1;//算术运算符 echo $x+=5;//赋值运算符 echo "<br/>"; echo $x++; ec ...

  5. 2.1 <script>元素【JavaScript高级程序设计第三版】

    向 HTML 页面中插入 JavaScript 的主要方法,就是使用<script>元素.这个元素由 Netscape 创造并在 Netscape Navigator 2 中首先实现.后来 ...

  6. tp5.0初入

    1.目录结构 |-application 应用目录 是整个网站的核心 |---|---index 前台目录 |---|-----|---controller 控制器 |---|-----|---mod ...

  7. laravels -- Swoole加速php

    LaravelS是一个胶水项目,用于快速集成Swoole到Laravel,然后赋予它们更好的性能.更多可能性. 环境 : ubuntu16 + nginx + php7.1 + LaravelS搭建高 ...

  8. html5的canvas绘制线条,moveTo和lineTo详解

    今天在看html5,里面新增的属性有一个canvas,它相当于一个画布你可以用js在里面画你想要的效果!我在w3c的手册里面看到用moveTo和lineTo绘制线条讲的不是很清楚,尤其是moveTo和 ...

  9. python中的文件操作小结2

    ''' #-----------文件修改---------- f=open("test_1",'r',encoding="utf-8") f2=open(&qu ...

  10. chroot: cannot run command `/bin/bash': No such file&nbs

    最近在使用chroot去重新的挂载一个根目录,总是出现上面的问题,很烦,好久了没有解决, 然后自己就写了一个复制依赖库的脚本,然后发现可以切换了,然后就重新试着去挂载根目录 终于发现了原因. ---- ...