https://scut.online/p/244

除了常规的求凸包求面积,还有一个判断点在凸包内,先找出点所在的三角扇区。

#include<bits/stdc++.h>
using namespace std;
#define ll long long /****************************凸包模板*******************************/ const double eps = 1e-; int sgn(double x) {
if(fabs(x) < eps)
return ;
if(x < )
return -;
else
return ;
} struct Point {
double x,y;
Point() {}
Point(double _x,double _y) {
x = _x;
y = _y;
} Point operator -(const Point &b)const {
return Point(x - b.x,y - b.y);
} //叉积
double operator ^(const Point &b)const {
return x*b.y - y*b.x;
} //点积
double operator *(const Point &b)const {
return x*b.x + y*b.y;
} void input() {
scanf("%lf%lf",&x,&y);
} void output() {
printf("(%.2f,%.2f)\n",x,y);
} }; struct Line { Point s,e; Line() {} Line(Point _s,Point _e) { s = _s;
e = _e; } }; //*两点间距离 double dist(Point a,Point b) { return sqrt((a-b)*(a-b)); } /* * 求凸包,Graham算法 * 点的编号0~n-1 * 返回凸包结果Stack[0~top-1]为凸包的编号 */ const int MAXN = +; Point List[MAXN]; int Stack[MAXN];//用来存放凸包的点 int top;//表示凸包中点的个数 //相对于List[0]的极角排序 bool _cmp(Point p1,Point p2) {
double tmp = (p1-List[])^(p2-List[]);
if(sgn(tmp) > )
return true;
else if(sgn(tmp) == && sgn(dist(p1,List[]) - dist(p2,List[])) <= )
return true;
else
return false;
} Point p[MAXN]; void Graham(int n) {
Point p0;
int k = ;
p0 = List[];
//找最下边的一个点
for(int i = ; i < n; i++) {
if((p0.y>List[i].y) || (p0.y == List[i].y && p0.x > List[i].x) ) {
p0 = List[i];
k = i;
}
}
swap(List[k],List[]);
sort(List+,List+n,_cmp);
if(n == ) {
top = ;
Stack[] = ;
return;
}
if(n == ) {
top = ;
Stack[] = ;
Stack[] = ;
return ;
}
Stack[] = ;
Stack[] = ;
top = ;
for(int i = ; i < n; i++) {
while(top > && sgn((List[Stack[top-]]-List[Stack[top-]])^(List[i]-List[Stack[top-]])) <= )
top--;
Stack[top++] = i;
} for(int i=;i<top;i++){
p[i]=List[Stack[i]];
}
} bool inside(Point A) {
int l=,r=top-,mid;
while(l<=r) {
mid=(l+r)>>;
double a1=(p[mid]-p[])^(A-p[]);
double a2=(p[mid+]-p[])^(A-p[]);
if(sgn(a1)>=&&sgn(a2)<=) {
if(sgn((p[mid+]-p[mid])^(A-p[mid]))>=)
return true;
return false;
}
else if(a1<) {
r=mid-;
}
else {
l=mid+;
}
}
return false;
}
/****************************凸包模板*******************************/
int main() {
int n;
while(~scanf("%d",&n)){
double x,y;
for(int i=;i<n;i++) {
scanf("%lf%lf",&x,&y);
List[i].x=x;
List[i].y=y;
}
Graham(n);
/*for(int i=0; i<top; i++) {
List[Stack[i]].output();
}*/ double area=0.0;
Point o(,);
for(int i=; i<top; i++) {
area+=(List[Stack[i]]-o)^(List[Stack[(i+top-)%top]]-o);
} area*=0.5;
area=fabs(area); printf("%.6f\n",area); int m;
scanf("%d",&m);
while(m--){
double x,y;
scanf("%lf%lf",&x,&y);
if(inside(Point(x,y))){
printf("Yes\n");
}
else{
printf("No\n");
}
}
}
}

SCUT - 244 - 全新的游戏 - 凸包的更多相关文章

  1. 映众全新游戏内存条发布:单条16GB 最高4000MHz

    近日,显卡与内存厂商映众(INNO3D)推出了一款全新的游戏内存条产品——iCHILL Memory. iCHILL Memory是DDR4内存,单条容量有4GB-16GB可选,内存频率有2400MH ...

  2. 爆款AR游戏如何打造?网易杨鹏以《悠梦》为例详解前沿技术

    本文来自网易云社区. 7月31日,2018云创大会游戏论坛在杭州国际博览中心103B圆满举行.本场游戏论坛聚焦探讨了可能对游戏行业发展有重大推动的新技术.新实践,如AR.区块链.安全.大数据等. 网易 ...

  3. 如何平衡MMO游戏

    转自:http://blog.sina.com.cn/s/blog_9f56a65f01013eti.html 前言 这是一篇出自国外博客“Elder Game”的一篇文章,笔者觉得里面很多东西说的很 ...

  4. 游戏数值——LOL篇 以LOL为起点-说游戏数值设计核心思路

      附     文   文档在今年三月份我动笔写了一小部分,但当时思路凌乱,行文梗阻,于是丢在一边构思了半年,现在又回过头来慢慢写,希望能写好写完吧,初衷是希望即时萌新也能看懂,但是好像并不能行——本 ...

  5. (转)iOS Wow体验 - 第三章 - 用户体验的差异化策略

    本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第三章译文精选,其余章节将陆续放出.上一篇:Wow ...

  6. [Cocos2d-x]Lua 资源热更新

    什么是热更新 所谓的热更新,指的是客户端的更新. 大致的流程是,客户端在启动后访问更新的URL接口,根据更新接口的反馈,下载更新资源,然后使用新的资源启动客户端,或者直接使用新资源不重启客户端. 热更 ...

  7. js实现在光标的位置 添加内容

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. 朴素贝叶斯文本分类实现 python cherry分类器

    贝叶斯模型在机器学习以及人工智能中都有出现,cherry分类器使用了朴素贝叶斯模型算法,经过简单的优化,使用1000个训练数据就能得到97.5%的准确率.虽然现在主流的框架都带有朴素贝叶斯模型算法,大 ...

  9. 专家来“搞”| IoT DevKit,物联网界新手大礼包等你来拿

    专家来“搞” 这是一档基于近期热门云技术,邀请 IT 和开发领域的资深专家,来给大家分享不同领域的云技术操作环境及开发过程中经常遇到的痛点和解决方案,与实战紧密相连,帮助大家学习知识点,顺利解决工作中 ...

随机推荐

  1. [ACM] ZOJ 3725 Painting Storages (DP计数+组合)

    Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with ...

  2. MRP Force Reservation的作用

    生产单根据BOM计算出相应的物料需求,生产领料单stock.picking ( internal moves) Stock.picking使用工作流自动计算库存量,如果库存量够,则使用 test_as ...

  3. POJ - 3233 Matrix Power Series (矩阵等比二分求和)

    Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + - + Ak. ...

  4. INAPP

    1. Login API : 接口為您提供了我們的登入服務,可以讓使用者透過facebook帳號登入我們的服務,在您呼叫此API後,可以得到 使用者的UUID(Unique UID為使用者在平台的唯一 ...

  5. 基于bootstrap_后台管理

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. JavaScript提高:001:ASP.NET使用easy UI

    jQuery EasyUI是一组基于jQuery的UI插件集合.能够简洁的开发出功能多内容丰富的界面,而不须要开发人员自己费力的写那些复杂的js代码.本文简介在ASP.NET开发中引用这些js文件和样 ...

  7. 第一讲:使用html5——canvas绘制奥运五环

    <html> <head> <title>初识canvas</title> </head> <body> <canvas ...

  8. Region Range

    三篇文章了解 TiDB 技术内幕 - 说存储| PingCAP https://pingcap.com/blog-cn/tidb-internal-1/ 对于一个 KV 系统,将数据分散在多台机器上有 ...

  9. 使用POCO发送HTTP(S)请求

    POCO GitHub地址https://github.com/pocoproject/poco http_example.cpp #include <iostream> #include ...

  10. Hive中的一些点

    hive严格模式 Hive中Order by和Sort by的区别是什么? hive中order by,sort by, distribute by, cluster by作用以及用法 Hadoop ...