POJ 3348 Cows | 凸包模板题
题目:
给几个点,用绳子圈出最大的面积养牛,输出最大面积/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 | 凸包模板题的更多相关文章
- 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 [凸包 面积]
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9022 Accepted: 3992 Description ...
- POJ 3348 Cows 凸包 求面积
LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...
- poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7038 Accepted: 3242 Description ...
- POJ 3348 Cows | 凸包——童年的回忆(误)
想当年--还是邱神给我讲的凸包来着-- #include <cstdio> #include <cstring> #include <cmath> #include ...
- poj 3348 Cow 凸包面积
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8122 Accepted: 3674 Description ...
- Sliding Window POJ - 2823 单调队列模板题
Sliding Window POJ - 2823 单调队列模板题 题意 给出一个数列 并且给出一个数m 问每个连续的m中的最小\最大值是多少,并输出 思路 使用单调队列来写,拿最小值来举例 要求区间 ...
- POJ 2186:Popular Cows Tarjan模板题
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25945 Accepted: 10612 De ...
随机推荐
- 在 publicId 和 systemId 之间需要有空格。
spring applicationContext_datasource.xml中约束错误 org.springframework.beans.factory.xml.XmlBeanDefiniti ...
- 转 MYSQL 命令行大全 (简洁、明了、全面)
MYSQL常用命令 .导出整个数据库 mysqldump -u 用户名 -p –default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1 ...
- 解决SecureCRT远程Linux遇到文件不能直接往CRT里直接拖入的问题
不能拖入到CRT的第一个原因可能是Options-->Global Options-->Terminal中的Mouse下的Copy on select没有勾选.当发现自己勾选了也不能往里面 ...
- Sublime package control错误:There are no packages available for installation
查了很多资料都没有解决. 改host---无效 复制一个文件的什么的,我看到版本比我的旧,就没有用 终于最后一个解决了.最终解决方案 解决: 更新下Package Control就好了: prefer ...
- 【异常】The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.
异常错误:The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone ...
- WPF点击不同界面上的按钮实现界面切换
原文:WPF点击不同界面上的按钮实现界面切换 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_29844879/article/details/ ...
- Android Studio快速的接受一个项目
1.关键词搜索法,搜索这个词,然后仔细的去找找.肯定可以找到的,虽然可能会有一些奔波. 2.Android device moniter ,可以抓屏幕,看布局,而且可以看到资源id.看到资源id,你说 ...
- 2.栅格的类中同时设置col-md-* col-sm-*的作用
1.一般设定成这样的话,在小屏幕上会堆叠在一起 <div class="row"> <div class="col-md-4 ">COL ...
- 安装macports
Mac下面除了用dmg.pkg来安装软件外,比较方便的还有用MacPorts来帮助你安装其他应用程序,跟BSD中的ports道理一样.MacPorts就像apt-get.yum一样,可以快速安装些软件 ...
- TCP重组问题
今天问题: vqmon 测试一pcap抓包文件18.pcap.发现实际输出的视频分片信息和抓包不符合. ===>pts : 00:00:33 Too much data in TCP recei ...