http://poj.org/problem?id=3348 (题目链接)

题意

  给出平面上n个点,以这n个点中的一些围成的多边形面积 div 50的最大值。

Solution

  凸包求面积。

  很好做,构造完凸包后从栈底开始向上求叉乘之和,也就是将凸包分成许多小三角形求面积和。

代码

// poj3348
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<map>
#define inf 2147483640
#define LL long long
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);
using namespace std;
inline LL getint() {
LL x=0,f=1;char ch=getchar();
while (ch>'9' || ch<'0') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
return x*f;
} const int maxn=10010;
struct point {int x,y;}p[maxn];
int s[maxn],n,top; int cross(point p0,point a,point b) {
return (a.x-p0.x)*(b.y-p0.y)-(a.y-p0.y)*(b.x-p0.x);
}
double dis(point a,point b) {
return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool cmp(point a,point b) {
int t=cross(p[1],a,b);
if (t>0) return 1;
else if (t==1 && dis(a,p[1])<dis(b,p[1])) return 1;
else return 0;
}
void Graham() {
if (n==1) s[top=1]=1;
else if (n==2) {s[top=1]=1;s[++top]=2;}
else {
s[top=1]=1;s[++top]=2;
for (int i=3;i<=n;i++) {
while (top>1 && cross(p[s[top-1]],p[s[top]],p[i])<=0) top--;
s[++top]=i;
}
}
}
double Size() {
point p0=p[s[1]];
double sum=0;
for (int i=3;i<=top;i++) sum+=cross(p0,p[s[i-1]],p[s[i]]);
return sum/2;
}
int main() {
while (scanf("%d",&n)!=EOF) {
int k=1;
for (int i=1;i<=n;i++) {
scanf("%d%d",&p[i].x,&p[i].y);
if (p[i].x<p[k].x || (p[i].x==p[k].x && p[i].y<p[k].y)) k=i;
}
point p0=p[k];
p[k]=p[1];p[1]=p0;
sort(p+2,p+1+n,cmp);
Graham();
printf("%d\n",(int)Size()/50);
}
return 0;
}

  

【poj3348】 Cows的更多相关文章

  1. 【BZOJ1720】[Usaco2006 Jan]Corral the Cows 奶牛围栏 双指针法

    [BZOJ1720][Usaco2006 Jan]Corral the Cows 奶牛围栏 Description Farmer John wishes to build a corral for h ...

  2. 【POJ3621】Sightseeing Cows 分数规划

    [POJ3621]Sightseeing Cows 题意:在给定的一个图上寻找一个环路,使得总欢乐值(经过的点权值之和)/ 总时间(经过的边权值之和)最大. 题解:显然是分数规划,二分答案ans,将每 ...

  3. 【POJ2182】Lost Cows

    [POJ2182]Lost Cows 题面 vjudge 题解 从后往前做 每扫到一个点\(i\)以及比前面小的有\(a[i]\)个数 就是查询当前的第\(a[i]+1\)小 然后查询完将这个数删掉 ...

  4. 【POJ3621】【洛谷2868】Sightseeing Cows(分数规划)

    [POJ3621][洛谷2868]Sightseeing Cows(分数规划) 题面 Vjudge 洛谷 大意: 在有向图图中选出一个环,使得这个环的点权\(/\)边权最大 题解 分数规划 二分答案之 ...

  5. 【2186】Popular Cows(强连通分支及其缩点)

    id=2186">[2186]Popular Cows(强联通分支及其缩点) Popular Cows Time Limit: 2000MS   Memory Limit: 65536 ...

  6. tarjan缩点练习 洛谷P3387 【模板】缩点+poj 2186 Popular Cows

    缩点练习 洛谷 P3387 [模板]缩点 缩点 解题思路: 都说是模板了...先缩点把有环图转换成DAG 然后拓扑排序即可 #include <bits/stdc++.h> using n ...

  7. 【LeetCode】299. Bulls and Cows 解题报告(Python)

    [LeetCode]299. Bulls and Cows 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题 ...

  8. 【dfs】BZOJ1703-[Usaco2007 Mar]Ranking the Cows 奶牛排名

    [题目大意] 农夫约翰有N(1≤N≤1000)头奶牛,每一头奶牛都有一个确定的独一无二的正整数产奶率.约翰想要让这些奶牛按产奶率从高到低排序,约翰已经比较了M(1≤M≤10000)对奶牛的产奶率,但他 ...

  9. 【BZOJ】1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名

    [题意]给定n头牛和m对大小关系,求最坏情况下至少还需要比较几对奶牛的大小(在未确定顺序的奶牛对中随机比较) [算法]floyd求传递闭包 [题解]可达说明大小已知,则不可达点对数量就是最少比较次数. ...

随机推荐

  1. 第23章 SEH结构化异常处理(3)_终止处理程序

    23.3 终止处理程序 23.3.1 程序的结构 (1)框架 __try{ //被保护的代码块 …… } __finally{ //终止处理 } (2)__try/__finally的特点 ①fina ...

  2. 在Unity中为模型使用表情

    在游戏中让角色能够拥有表情,是我一直很想实现的一件事情,今天搜索了一下这方面的资料,找到两个解决方案. MMD For Unity GitHub:https://github.com/mmd-for- ...

  3. java9-5 修饰符

    1. 修饰符: 权限修饰符:private,默认的,protected,public 状态修饰符:static,final 抽象修饰符:abstract 类: 权限修饰符:默认修饰符,public 状 ...

  4. 转: CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法

    from: http://www.linuxde.net/2014/05/15576.html CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法 2014/05/ ...

  5. PHP安装memcache扩展接口步骤

    1.将php_memcache.dll文件保存到php的应用程序扩展ext目录中 2.在php.ini配置文件添加扩展的位置,加入一行extension=php_memcache.dll 3.重新启动 ...

  6. mysqli_stmt预处理类

    <?php  $mysqli=new mysqli("localhost", "root", "123456", "xsph ...

  7. iOS -数据库网络之xml解析之第三方解析XML

    1.导入第三方插件(GDalaXMLNode)   2.第三方插件配置   libxml/tree.h 路径   在项目属性中--Bulid Settings中搜索 Search   --Search ...

  8. [资料]常用Windows CMD指令

    1. 查找80端口开放情况 netstat -aon|findstr “80″ 2. 用netstat查询端口占用程序的PID,显示列表的最后一列就是占用程序的PID,然后再利用tasklist找到这 ...

  9. PC网站应用接入微信登录

    参考文档: https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&ve ...

  10. jdbc 得到表结构、主键

    jdbc 得到表结构.主键 标签: jdbctablenullschema数据库mysql 2012-02-16 22:13 11889人阅读 评论(0) 收藏 举报  分类: Java(71)  假 ...