求凸包面积。求结果后不用加绝对值,这是BBS()排序决定的。

//Ps 熟练了template <class T>之后用起来真心方便= =

//POJ 3348
//凸包面积
//1A 2016-10-15 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#define MAXN (10000 + 10) struct point{
int x, y;
point(){}
point(int X, int Y): x(X), y(Y){}
friend int operator ^ (const point &p1, const point &p2){
return p1.x * p2.y - p1.y * p2.x;
}
friend point operator >> (const point &p1, const point &p2){
return point(p2.x - p1.x, p2.y - p1.y);
}
friend bool operator < (const point &p1, const point &p2){
return (p1.x < p2.x)||(p1.x == p2.x)&&(p1.y < p2.y);
}
}pt[MAXN]; template <class T>
void swap(T &a, T & b){
T t = a;
a = b;
b = t;
} template <class T>
void BBS(T a[], int n){
for (int i = 0; i < n; i++)
for (int j = 0; j < i; j++)
if (a[i] < a[j]) swap(a[j], a[i]);
} double convex_hull(point p[], int n){
int cur = 0;
double area = 0;
BBS(p, n);
while (1){
int tmp = - 1;
for (int i = 0; i < n; i++){
if (cur != i){
if (!(tmp + 1)||((p[cur] >> p[i]) ^ (p[cur] >> p[tmp])) > 0)
tmp = i;
}
}
if (tmp + 1){
area += p[cur] ^ p[tmp];
}
if (!tmp||!(tmp + 1)) return area / 2;
cur = tmp;
}
} int main(){
int n;
freopen("fin.c", "r", stdin);
scanf("%d", &n);
for (int i = 0; i < n; i++){
scanf("%d%d", &pt[i].x, &pt[i].y);
}
printf("%d\n", int(convex_hull(pt, n)/50));
}

POJ 3348 - Cows 凸包面积的更多相关文章

  1. POJ 3348 Cows [凸包 面积]

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

  2. poj 3348 Cow 凸包面积

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

  3. POJ 3348 Cows 凸包 求面积

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

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

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

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

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

  6. POJ 3348 Cows | 凸包模板题

    题目: 给几个点,用绳子圈出最大的面积养牛,输出最大面积/50 题解: Graham凸包算法的模板题 下面给出做法 1.选出x坐标最小(相同情况y最小)的点作为极点(显然他一定在凸包上) 2.其他点进 ...

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

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

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

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

  9. POJ 3348 Cows

    题目大意: 给你n棵树,可以用这n棵树围一个圈,然后在圈里面可以养牛,每个牛需要50平方米的空间,问最多可以养多少牛? 其实就是求一个凸包,计算凸包面积,然后除以50,然后就得到答案,直接上模板了. ...

随机推荐

  1. Ant——ant的使用

    ---------------------------------------------------------------------------------------------------- ...

  2. locate无法open mlocate.db

    # locate xxxx locate: can not open () `/var/lib/mlocate/mlocate.db': No such file or directory 如果出现此 ...

  3. 九度oj 题目1034:寻找大富翁

    题目链接:http://ac.jobdu.com/problem.php?pid=1034 题目描述:     浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁. 输入:     输入包含多组测试用 ...

  4. BYTE 和字符串转换

    string hanzi = "汉字"; byte[] arr = System.Text.Encoding.UTF8.GetBytes(hanzi); string temp = ...

  5. Geneve: Generic Network Virtualization Encapsulation

    Earlier this year, VMware, Microsoft, Red Hat and Intel published an IETF draft on Generic Network V ...

  6. 【1】第一次电话面试---上海EMC

    时间是2016//11月,投的是上海的EMC2公司的JavaWeb开发岗,第一次接到的电话面试,问的题目很基础基础,很遗憾,本人在掌握的太不好,回答的很乱,目测定挂.下面记下HR问的问题及回答. 首先 ...

  7. bzoj2518: [Shoi2010]滚动的正四面体

    Description 正四面体总共有4个面,每个面都是一个正三角形.现在把它的一个面标记上字母A,如图 3中所示,A标记在底面上: 于是,这个正四面体的滚动过程就可以用一个只包含“L”“R”“B”的 ...

  8. 黄聪:如何关闭phpstorm的typo拼写检查

    文件-设置-编辑器-inspections-spelling-typo

  9. mysql 安装日志

    善于使用 mysqld.exe --console 来得到提示

  10. Spring技术揭幕----DispatcherServlet

    Spring MVC是一个MVC模式的实现.在Spring MVC的使用中,需要在web.xml中配置DispatcherServlet,也就是说其核心是一个Servlet,这个DispatcherS ...