SCUT - 244 - 全新的游戏 - 凸包
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 - 全新的游戏 - 凸包的更多相关文章
- 映众全新游戏内存条发布:单条16GB 最高4000MHz
近日,显卡与内存厂商映众(INNO3D)推出了一款全新的游戏内存条产品——iCHILL Memory. iCHILL Memory是DDR4内存,单条容量有4GB-16GB可选,内存频率有2400MH ...
- 爆款AR游戏如何打造?网易杨鹏以《悠梦》为例详解前沿技术
本文来自网易云社区. 7月31日,2018云创大会游戏论坛在杭州国际博览中心103B圆满举行.本场游戏论坛聚焦探讨了可能对游戏行业发展有重大推动的新技术.新实践,如AR.区块链.安全.大数据等. 网易 ...
- 如何平衡MMO游戏
转自:http://blog.sina.com.cn/s/blog_9f56a65f01013eti.html 前言 这是一篇出自国外博客“Elder Game”的一篇文章,笔者觉得里面很多东西说的很 ...
- 游戏数值——LOL篇 以LOL为起点-说游戏数值设计核心思路
附 文 文档在今年三月份我动笔写了一小部分,但当时思路凌乱,行文梗阻,于是丢在一边构思了半年,现在又回过头来慢慢写,希望能写好写完吧,初衷是希望即时萌新也能看懂,但是好像并不能行——本 ...
- (转)iOS Wow体验 - 第三章 - 用户体验的差异化策略
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第三章译文精选,其余章节将陆续放出.上一篇:Wow ...
- [Cocos2d-x]Lua 资源热更新
什么是热更新 所谓的热更新,指的是客户端的更新. 大致的流程是,客户端在启动后访问更新的URL接口,根据更新接口的反馈,下载更新资源,然后使用新的资源启动客户端,或者直接使用新资源不重启客户端. 热更 ...
- js实现在光标的位置 添加内容
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 朴素贝叶斯文本分类实现 python cherry分类器
贝叶斯模型在机器学习以及人工智能中都有出现,cherry分类器使用了朴素贝叶斯模型算法,经过简单的优化,使用1000个训练数据就能得到97.5%的准确率.虽然现在主流的框架都带有朴素贝叶斯模型算法,大 ...
- 专家来“搞”| IoT DevKit,物联网界新手大礼包等你来拿
专家来“搞” 这是一档基于近期热门云技术,邀请 IT 和开发领域的资深专家,来给大家分享不同领域的云技术操作环境及开发过程中经常遇到的痛点和解决方案,与实战紧密相连,帮助大家学习知识点,顺利解决工作中 ...
随机推荐
- IOS常见错误分析解决(一直更新) 你值得收藏-综合贴
-来自收藏总结 综合了好多的常见错误 1:clang failed with exit code 254 一:检測代码中 是否 有 NSLog 打印了 返回 void 的值. 2:Verify exi ...
- Ikki's Story IV - Panda's Trick (poj 3207 2-SAT)
Language: Default Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 131072K Total S ...
- php中的register_shutdown_function和fastcgi_finish_request
在php中又两个方法都是在请求快结束的时候执行.方法名分别是 register_shutdown_function和fastcgi_finish_request.虽然执行的时机差不多,但是功能和应用场 ...
- 一起来当网管(一)——Windows Server上的DHCP配置
学校实验室里大大小小设备还不少,网络环境虽说不复杂,但也比家用的复杂一些.就当练练手吧,刚好写点文章,免得以后实验室网络没人管了.那么就先从DHCP的配置来讲吧! 1.DHCP是什么.有什么用 DHC ...
- 从.Net版本演变看String和StringBuilder性能之争
在C#中string关键字的映射实际上指向.NET基类System.String.System.String是一个功能非常强大且用途非常广泛的基类,所以我们在用C#string的时候实际就是在用.NE ...
- LeetCode(3)题解: Longest Palindromic Substring
https://leetcode.com/problems/longest-palindromic-substring/ 题目: Given a string S, find the longest ...
- UVA - 11019 Matrix Matcher hash+KMP
题目链接:传送门 题解: 枚举每一行,每一行当中连续的y个我们hash 出来 那么一行就是 m - y + 1个hash值,形成的一个新 矩阵 大小是 n*(m - y + 1), 我们要找到x*y这 ...
- 我遇到的错误curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused
今天我用curl命令,无论如何都是出现: curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused 找了很久,不知道 ...
- Rowkey is the Crux Rowkey Design
Apache HBase ™ Reference Guide http://hbase.apache.org/book.html#rowkey.design The Effect of ColumnF ...
- powerdesigner 导入mysql数据库(步骤及注意点)
参考博客 PowerDesigner中导入MYSQL数据库结构的步骤 mysql ODBC 在64位下提示找不到odbc驱动问题 PowerDesigner逆向工程导入MYSQL数据库总结