原题链接:http://poj.org/problem?id=3348
博主的中文题面:
https://www.luogu.org/problemnew/show/T23970

Cows

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 forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.

However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.

Input

The first line of input contains a single integer, n (1 ≤ n ≤ 10000), containing the number of trees that grow on the available land. The next n lines contain the integer coordinates of each tree given as two integers x and y separated by one space (where -1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10; 11) and (11; 11) is one metre).

Output

You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.

Sample Input

4
0 0
0 101
75 0
75 101

Sample Output

151

题目大意

求凸包面积

题解

求凸包的板子题,先按x为第一关键字,y为第二关键字排序,然后以左下角的点为起点(显然该点在凸包上),逆时针进行搜索(实际上因为我们排过序,就是遍历而已)。每次加入新元素时,将其与栈顶的两个点进行比较,如果新加入的点在栈顶两元素连线的右侧,那么弹出栈顶元素(根据凸包的定义,要求我们的路径是一直左转的),更新完毕后,再加入新元素即可。
求面积部分与POJ1654一致,最后记得除以50即可AC。

代码
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=1e4+5;
const int mod=2e3;
struct pt{int x,y;};
bool operator < (const pt &a,const pt &b){return a.x==b.x?a.y<b.y:a.x<b.x;}
pt operator - (pt a,pt b){pt r;r.x=a.x-b.x;r.y=a.y-b.y;return r;}
int operator * (pt a,pt b){return a.x*b.y-a.y*b.x;}
pt p[M],sta[M];
int top,n;
void in()
{scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d%d",&p[i].x,&p[i].y);
}
void tubao()
{sort(p+1,p+1+n);sta[0]=sta[1]=p[1];top=1;for(int i=2;i<=n;++i){while((sta[top]-sta[top-1])*(p[i]-sta[top-1])>0) --top;sta[++top]=p[i];}for(int i=n-1;i>=1;--i){while((sta[top]-sta[top-1])*(p[i]-sta[top-1])>0) --top;sta[++top]=p[i];}
}
int area(pt a,pt b)
{return 1ll*(a.x-b.x)*(a.y+b.y+2*mod);
}
void ac()
{long long ans=0;tubao();for(int i=1;i<top;++i){ans+=area(sta[i],sta[i+1]);}ans=ans>0?ans:-ans;printf("%lld",ans/100);
}
int main()
{in();ac();return 0;
}

POJ3348 Cows相关推荐

  1. POJ3348 Cows【凸包+多边形求面积】

    POJ3348Cows 凸包+多边形求面积 个人分类: 计算几何凸包 Language: Default Cows Time Limit: 2000MS   Memory Limit: 65536K ...

  2. POJ-3348 Cows

    模板题,先用Graham求凸包,然后用多边形面积公式求凸包面积,除以50取整就是答案 #include<iostream> #include<cstdio> #include& ...

  3. 竞赛程序设计知识要点图谱

    一.基础算法 1.枚举法 POJ1248 Safecracker HDU1172 猜数字 POJ1543 Perfect Cubes POJ1046 Color Me Less 2.递归法:Hanoi ...

  4. Milking Cows 挤牛奶

    1.2.1 Milking Cows 挤牛奶 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 554  Solved: 108 [Submit][Stat ...

  5. 二分搜索 POJ 2456 Aggressive cows

    题目传送门 1 /* 2 二分搜索:搜索安排最近牛的距离不小于d 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #incl ...

  6. POJ 2456 Aggressive cows(二分答案)

    Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22674 Accepted: 10636 Des ...

  7. 洛谷——P2341 [HAOI2006]受欢迎的牛//POJ2186:Popular Cows

    P2341 [HAOI2006]受欢迎的牛/POJ2186:Popular Cows 题目背景 本题测试数据已修复. 题目描述 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就是一头明星奶牛.所 ...

  8. [USACO16JAN]Angry Cows S[二分+贪心]

    题意:Bessie 设计了一款新游戏:Angry Cows.在这个游戏中,玩家发射奶牛,每头奶牛落地时引爆一定范围内的干草.游戏的目标是使用一组奶牛引爆所有干草. N 捆干草排列在数轴上的不同位置.第 ...

  9. A - Til the Cows Come Home POJ - 2387

    A - Til the Cows Come Home POJ - 2387 最短路 #include<iostream> #include<cstdio> #include&l ...

  10. bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛*

    bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛 题意: 求最长单调递增子序列,序列大小≤5000 题解: 蒟蒻弱写了一个O(n^2)的. 代码: 1 #include ...

最新文章

  1. eclipse运行程序时只有run on server
  2. 计算机科学家证明,为什么更大的神经网络可以做得更好
  3. Go 语言 Session机制和 Cookie机制
  4. Centos下搭建ftp服务器
  5. boost::multi_array模块实现打印数组相关的测试程序
  6. 关于写好文章的3个心法和5点技巧
  7. 后台无刷新修改字段js
  8. Dreamoon Likes Coloring CodeForces - 1330C(贪心+思维)
  9. 简单实现顶部固定,中部自适应布局
  10. 红旗河最早设计计算机的目的,论红旗河的利弊及其替代方案
  11. python关闭对象语法_Python基础及语法(七)
  12. 安兔兔2019年1月安卓手机排行榜发布:小米无愧性价比之王
  13. 提取图像色彩主色调工具
  14. 计算机应用基本技能题库,计算机应用基本技能技能考试题库.pdf
  15. GetModuleFileNameA函数与GetCurrentDirectoryA函数
  16. 关于DM8168中移植算法速度慢、效率低的新发现
  17. 人力资源管理系统erp
  18. 2019软考软件评测师考试大纲
  19. 从入门到放弃:微信小程序入门个人指南Day 4
  20. 基于SpringBoot的外卖点餐管理系统

热门文章

  1. Hugging Face Course-Diving in 抱抱脸 Tokenizers library (WordPiece tokenization Unigram tokenization)
  2. Tomcat找不到Controller里面的路径
  3. 微星P55-主板是怎样造出来的
  4. [物理学与PDEs]第1章第9节 Darwin 模型 9.3 Darwin 模型
  5. 线程间的通信之wait和notify的使用
  6. 有界、无界队列对ThreadPoolExcutor执行的影响
  7. ElasticSearch全文搜索引擎之term和match的区别
  8. MyCat分库分表入门示例
  9. RocketMQ消费端消息回退(消费重试)机制源码解析
  10. Facebook全面实施GDPR 用户Pages页面被随意锁定