http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=45

套模板即可。

一道类似的题:LightOJ 1190 Sleepwalking

完整代码:

/*0.018s*/#include<bits/stdc++.h>
using namespace std;struct P
{int x, y;P(int x = 0, int y = 0): x(x), y(y) {}bool read(){return ~scanf("%d%d", &x, &y);}bool operator < (const P& p) const ///加cosnt以便sort调用,其他函数不加const对速度没有影响{return x < p.x || x == p.x && y < p.y;}P operator + (P p){return P(x + p.x, y + p.y);}P operator - (P p){return P(x - p.x, y - p.y);}int dot(P p){return x * p.x + y * p.y;}int det(P p){return x * p.y - y * p.x;}
} a[105], ans[25][105];int n, len, Size[25];
bool vis[25];///求凸包
void convex_hull(int country)
{sort(a, a + n);len = 0;int i;for (i = 0; i < n; ++i){while (len >= 2 && (ans[country][len - 1] - ans[country][len - 2]).det(a[i] - ans[country][len - 1]) <= 0)--len;ans[country][len++] = a[i];}int tmp = len;for (i = n - 2; i >= 0; --i){while (len > tmp && (ans[country][len - 1] - ans[country][len - 2]).det(a[i] - ans[country][len - 1]) <= 0)--len;ans[country][len++] = a[i];}--len;ans[country][len] = ans[country][0]; ///okSize[country] = len;
}///点q在线段p1p2上
inline bool on_seg(P p1, P p2, P q)
{return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}///点q在country内
bool in_area(int country, P q)
{int cnt = 0, k, d1, d2;for (int i = 0; i < Size[country]; ++i){if (on_seg(ans[country][i], ans[country][i + 1], q)) return false;k = (ans[country][i + 1] - ans[country][i]).det(q - ans[country][i]);d1 = ans[country][i].y - q.y;d2 = ans[country][i + 1].y - q.y;if (k > 0 && d1 <= 0 && d2 > 0) ++cnt;if (k < 0 && d1 > 0 && d2 <= 0) --cnt;}return cnt != 0;
}int area(int country)
{int sum = 0;for (int i = 0; i < Size[country]; ++i)sum += ans[country][i].det(ans[country][i + 1]);return sum;
}int main()
{int country = 0, i;for (; scanf("%d", &n), n > 0; ++country){for (i = 0; i < n; ++i) a[i].read();convex_hull(country);}int sumA = 0;P p;while (p.read())for (i = 0; i < country; ++i)if (!vis[i] && in_area(i, p)){vis[i] = true;sumA += area(i);}if (sumA & 1) printf("%d.50\n", sumA >> 1);else printf("%d.00\n", sumA >> 1);return 0;
}

UVa 109 SCUD Busters (凸包面积判断点是否在凸包内部)相关推荐

  1. UVA 109 SCUD Busters【凸包模拟题】

    题目大意:世界由几个互不重叠领土但彼此敌对的国家组成,每个国家有一个发电站,负责给本国发电. 1,给出每个国家的建筑数(包括发电站和房子数),每个国家用最少的围墙将本国保护起来(凸包): 2,现在有不 ...

  2. UVa 109 - SCUD Busters(凸包计算)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  3. uva 109 SCUD Busters

    原题: 109 SCUD Bust ers Background Some problems are difficult to solve but h e a simplification that ...

  4. uva 109 SCUD Busters

    题意:有很多国家,国家的边界是包括房子和发电站的凸包,当发动战争是,会用飞毛腿导弹摧毁对方的发电站,则这个国家就会灭亡,给出每个国家的点的集合,包括房子和发电站,给出炮弹可以打中的点,计算出被摧毁的国 ...

  5. UVa 109 - SCUD Busters

    题目:红警0 0?有一些国家,给出国家被围墙围了起来,围墙内的范围都属于这个国家,现在要发射一些导弹,如果导弹落到国家内,那对应的国家就会停电,现在问停电的总面积. 分析:计算几何.凸包.点与多边形关 ...

  6. UVa 109 - SCUD Busters(凸包)

    题意:输入n个国家,每个国家一些点,用围墙(多边形)围起来,围墙内的范围都属于这个国家,现在要发射一些导弹,如果导弹落到国家内,那对应的国家就会停电,现在问停电的总面积. 分析:1,求凸包,Graha ...

  7. UVA 109 || SCUD Busters(凸包面积计算

    = = 模板水题.看数据就可以做了. 输出被炸弹轰炸之后,所有王国停电的总面积,保留小数点后两位. 题目中说到每个王国的边界是围城这些点的最小周长,所以可以推出,每个王国都是一个凸包圈住的点集: 第一 ...

  8. poj 1264 || UVA 109 SCUD Busters

    UVA这题过得蛮多人的,觉得应该是个水题吧. 一读题,也不麻烦,给你N个王国,求下凸包,再求面积.给你一些炮弹,问炮弹炸掉的面积.(一个炮弹炸的话,整个王国都被炸了). 直接求凸包后,求出各个王国的面 ...

  9. UVa Problem 109 - SCUD Busters

    // UVa Problem 109 - SCUD Busters // Verdict: Accepted // Submission Date: 2011-11-24 // UVa Run Tim ...

最新文章

  1. 在Ubuntu 16.04.04 LTS上调研QUIC开源项目minq笔记
  2. jvm:运行时数据区
  3. T-SQL - 访问远程数据库并对其数据表进行操作
  4. keil C 51 strlen库函数使用
  5. SAP Marketing Cloud的几大核心模块讲解
  6. 学计算机单招可以报那几个公立学校,为什么要选择公办单招学校,四川公办单招学校有哪些?...
  7. 伤感网络验证系统_知网查重报告单能造假?验证报告单真伪时,知网只给了这一个办法...
  8. 情人节:找一个程序员当老公的10大好处
  9. cnn输入层_一文掌握CNN卷积神经网络
  10. Eclipse中 Project facet jst.web.jstl has not been defined.解决方案
  11. mysql 主主_MySQL双主(主主)架构
  12. ionic3学习之懒加载
  13. linux运维命令3
  14. 怎么写linux的sh文件,linux – 什么是.sh文件?
  15. fl2440第一次烧录
  16. IDEA新手使用教程(详解)
  17. TLQ的安装路径不存在或不正确
  18. jQuery排他思想(siblings)
  19. 高德地图插件的简单使用
  20. vue项目用antv/g6做网络拓扑图

热门文章

  1. inventor2014出现inventor应用程序错误0xc0000142
  2. 月PV破15亿:Tumblr架构揭密
  3. Google谷歌排名优化圣经
  4. 凸透镜成像规律的证明
  5. 在 icesword darkspy等入侵检测下隐藏文件的方法 【祝大家国庆快乐!】
  6. 分子模拟-学习笔记(二)
  7. 屏蔽网页广告的插件Adblock-Plus和Adblock-Super
  8. 阿里云Redis典型场景:如何构建可扩展通用排行榜系统
  9. 2021直击大厂前端开发岗位面试题
  10. mysql中的正则操作 匹配手机号,匹配中文,替换