//uva 109 SCUD Busters-AC-Upgraded version
//AC By Warteac
//Runtime:0.009s
//2013-5-16
/*
输入:
第一行的整数,表示输入点的个数
的二行开始,每两个整数表示一个点的坐标
最后一行可以是第一个点(封闭型),也可以是最后一个点(不封闭),但都表示一个封闭的多边形
可以多点共线
结果:
凸包的结果存放于grham_scan()的第二个参数
凸包的顺序是逆时针
构造成功返回true
*/
#include<iostream>
#include<cstdio>
#include<vector>
#include<stack>
#include <iomanip>
#include<algorithm>
#include<cmath>
using namespace std;
typedef int PType;//定义点的类型
///
struct Point{
PType x,y;
Point(PType a = 0, PType b = 0){x  = a; y = b;}
void print(){cout << "x = " << x << "y = " << y << endl;}
Point operator -(Point p){return Point(x - p.x, y - p.y);}
}pBase;//最左下的点
typedef Point Vector;//向量
int direction(Vector v1,Vector v2){//求两个向量的叉积
return (v1.x*v2.y-v1.y*v2.x);
}
bool cmp(Point p1, Point p2){//比较函数
int d = direction(p1 - pBase, p2 - pBase);
if(d == 0){//极角相同
return abs(p1.x) < abs(p2.x);//距离从小到大排
}else {
return d < 0;//按逆时针排序
}
}
bool grham_scan(vector <Point> p , vector <Point> &parray){//求凸包的算法
//find first point p0 with minimum y-coordinate or minimun x-coordinate if y are the same
int index = 0;
for(int i = 1; i < p.size(); i++){
if(p[i].y < p[index].y ||(p[i].y == p[index].y && p[i].x < p[index].x))
index = i;
}
swap(p[0],p[index]);
pBase = p[0];
sort(p.begin()+1,p.end(),cmp);
//get the convex hull from p
parray.clear();
parray.push_back(p[0]);
parray.push_back(p[1]);
p.push_back(p[0]);
for(int i = 2; i < p.size(); i++){
Vector v1 (p[i].x - parray.back().x, p[i].y - parray.back().y);
Vector v2 (parray.back().x - (parray.end()-2)->x, parray.back().y - (parray.end()-2)->y);
int d = direction(v2,v1);
if(d <= 0) {parray.push_back(p[i]);}
else if(d > 0){
parray.pop_back();i--;
}
}
return true;
}
int areaOfPolygon(vector <Point> &vecCH) {//求凸多边形的面积
int nArea = 0;
for (vector <Point>::iterator i = vecCH.begin(); i != vecCH.end() - 1; ++i) {
nArea += (i + 1)->x * i->y - i->x * (i + 1)->y;
}
return nArea;
}
bool inPolygon(Point pt, vector <Point> &vecCH) {//判断点是否在多边形内部
for (vector <Point>::iterator i = vecCH.begin(); i != vecCH.end() - 1; ++i) {
int nX1 = pt.x - i->x, nY1 = pt.y - i->y;
int nX2 = (i + 1)->x - i->x, nY2 = (i + 1)->y - i->y;
if (nX1 * nY2 - nY1 * nX2 < 0) {
return false;
}
}
return true;
}
//
int main(){
int sites;
PType x,y;
vector <Point> v;
Point t,mi;
vector < vector <Point> >  p;//convex hull
int aflag[105] = {0};
int area = 0;
//input kingdom
while(cin >> sites && sites != -1){
v.clear();
vector <Point> temp;//one convex hull
while(sites--){
cin >> t.x >> t.y;
v.push_back(t);
}
//computing convex hull
if(grham_scan(v,temp) == true){
p.push_back(temp);//all convex hull
}
}
//input missile landings
while(cin >> mi.x >> mi.y){
for(int j = 0; j < p.size(); j++){
if((inPolygon(mi,p[j]) == true) && aflag[j] != 1){
aflag[j] = 1;
area += areaOfPolygon(p[j]);
break;
}
}
}
cout << setiosflags(ios::fixed) << setprecision(2);
cout << (double)area/2.0 << endl;
return 0;
}

uva 109 SCUD Busters-AC-Upgraded version相关推荐

  1. uva 109 SCUD Busters

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

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

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

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

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

  4. uva 109 SCUD Busters

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

  5. poj 1264 || UVA 109 SCUD Busters

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

  6. UVa 109 - SCUD Busters

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

  7. UVa 109 SCUD Busters (凸包面积判断点是否在凸包内部)

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

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

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

  9. UVa 109 - SCUD Busters(凸包)

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

  10. UVa Problem 109 - SCUD Busters

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

最新文章

  1. 企业网络安全之安全维度
  2. 在C/C++中嵌入Python
  3. linux光盘补救,Linux_忘记root密码时使用Linux系统光盘进行补救的方法,救援模式即rescue ,这个模式主 - phpStudy...
  4. SaaS 模式云数据仓库 MaxCompute 数据安全最佳实践
  5. 猪八戒玉华王:老码农的7项灵魂思考
  6. 【JUC】JDK1.8源码分析之ConcurrentSkipListMap(二)
  7. 生产环境中CentOS5.6下配置LVS(续)
  8. redis统计用户日活量_【赵强老师】Redis案例分析:用setbit统计活跃用户
  9. 降维系列之 LTSA 局部切空间排列
  10. OPPO小布助手算法系统的探索、实践与思考
  11. php项目经验总结,php项目心得以及总结
  12. MaskRCNN识别Pascal VOC 2007
  13. 基于xlsx-populate实现的前端埋点导出
  14. 2019年—BAT大型互联网企业刚出炉的一套面试题(Java岗)
  15. 傲慢与偏见之 - 轮到我们领先了
  16. 《金刚经说什么》诗词辑录
  17. 双硬盘安装Win10 Ubuntu20.04.1 双系统
  18. 苹果iOS系统最新市占率统计:iOS 11份额达到52%
  19. GAN动漫人像生成实现(附带源码)
  20. 创业公司如何设计合伙人股权的进入和退出机制

热门文章

  1. C盘清理瘦身就这三招,收好下次不必到处找。
  2. linux用dd工具制作img镜像文件
  3. 异地访问公司的ERP解决方案(完美部署上线,超级详细)
  4. MACOS Dock栏自动显示和隐藏取消延迟
  5. 大数据时代,主要包含哪些挑战?
  6. selenium抓取苏宁图书
  7. python开发视频播放器_python_十几行代码实现简单播放器
  8. java毕业设计项目源代码javaweb租车汽车租赁汽车出租管理系统
  9. 计算机用公式求指数用什么函数,Excel计算指数分布: EXPONDIST函数的详细说明
  10. python反编译luac_LuaJIT反编译总结