博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
E. 打击判定 判断矩形是否相交
阅读量:4314 次
发布时间:2019-06-06

本文共 1166 字,大约阅读时间需要 3 分钟。

有一个很明显的做法就是判断PointInPolygon 。枚举第二个矩形的点,是否在第一个矩形内,但是有bug

就是那种第二个矩形很大的那种,所以容易想到又枚举第一个矩形的点,看是否在第二个矩形里。

但是还是有bug。就是那种十字架的那种,大家都不属于大家,但是他们的对角线是相交的,判断对角线即可。

 

其实这题可以倒过来做。判断不相交。

1、如果第一个矩形的最大的x还比第二个矩形的最小的x小,那么永远不能相交。(画个图就可以)

2、.....类似的。

 

#include 
#include
#include
#include
#include
#define IOS ios::sync_with_stdio(false)using namespace std;#define inf (0x3f3f3f3f)typedef long long int LL;#include
#include
#include
#include
#include
#include
#include
void work() { int mi_x[33]; int mi_y[33]; int mx_x[33]; int mx_y[33]; int xx1, yy1, xx2, yy2; for (int i = 1; i <= 2; ++i) { cin >> xx1 >> yy1 >> xx2 >> yy2; mi_x[i] = min(xx1, xx2); mx_x[i] = max(xx1, xx2); mi_y[i] = min(yy1, yy2); mx_y[i] = max(yy1, yy2); } if (mi_x[1] > mx_x[2] || mx_x[1] < mi_x[2] || mx_y[1] < mi_y[2] || mi_y[1] > mx_y[2]) { cout << "Miss" << endl; } else { cout << "Hit" << endl; }}int main() {#ifdef local freopen("data.txt","r",stdin);#endif int t; cin >> t; while (t--) work(); return 0;}
View Code

 

转载于:https://www.cnblogs.com/liuweimingcprogram/p/6028738.html

你可能感兴趣的文章
我的大学生活-5-08-赵心宁
查看>>
入门阶段
查看>>
Android中使用http协议访问网络
查看>>
Join 与 CountDownLatch 之间的区别
查看>>
vc6下dll调试
查看>>
Ubuntu apt常用命令
查看>>
struts2 配置(部分)
查看>>
python代码迷之错误(ModuleNotFoundError: No module named 'caffe.proto')
查看>>
nodejs adm-zip 解压文件 中文文件名乱码 问题解决
查看>>
<Bootstrap> 学习笔记六. 栅格系统使用案例
查看>>
vector--C++ STL 学习
查看>>
蜕变成蝶~Linux设备驱动之异步通知和异步I/O
查看>>
jquery简单开始
查看>>
作业2
查看>>
ios上架报错90080,90087,90209,90125 解决办法
查看>>
给button添加UAC的小盾牌图标
查看>>
如何退出 vim
查看>>
Robberies
查看>>
get post 提交
查看>>
R安装
查看>>