E. 打击判定 判断矩形是否相交
2024-09-30 05:54:48
有一个很明显的做法就是判断PointInPolygon 。枚举第二个矩形的点,是否在第一个矩形内,但是有bug
就是那种第二个矩形很大的那种,所以容易想到又枚举第一个矩形的点,看是否在第二个矩形里。
但是还是有bug。就是那种十字架的那种,大家都不属于大家,但是他们的对角线是相交的,判断对角线即可。
其实这题可以倒过来做。判断不相交。
1、如果第一个矩形的最大的x还比第二个矩形的最小的x小,那么永远不能相交。(画个图就可以)
2、.....类似的。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
void work() {
int mi_x[];
int mi_y[];
int mx_x[];
int mx_y[];
int xx1, yy1, xx2, yy2;
for (int i = ; i <= ; ++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[] > mx_x[] || mx_x[] < mi_x[] ||
mx_y[] < mi_y[] || mi_y[] > mx_y[]) {
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 ;
}
最新文章
- asp.net中缓存的使用介绍一
- HTML中网页超链接设计
- 【poj2778-DNA Sequence】AC自动机+矩阵乘法
- ThreadLocal模式探索
- 【转】linux线程模型
- hibernate的id生成策略
- css3属性——border-radius用法
- c语言学习基础:[1]开发工具介绍
- Navicat for MySQL11--使用经验
- vi 编辑器笔记
- JDK8的新特性——Lambda表达式
- 权限认证 cookie VS token
- bash shell while语法
- JavaScript进阶(一)抽离公共函数
- github密钥
- centos7_ linux : Nginx安装手册
- Delphi自动适应屏幕分辨率的属性
- A crawler that sent a DELETE request to every resource it encountered
- StringDemo
- [转]如何远程连接运行OpenGL/Cuda 等GPU程序