E. 打击判定 判断矩形是否相交
有一个很明显的做法就是判断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 ;
}
E. 打击判定 判断矩形是否相交的更多相关文章
- Codeforces Round #524 (Div. 2) C. Masha and two friends 几何:判断矩形是否相交以及相交矩形坐标
题意 :给出一个初始的黑白相间的棋盘 有两个人 第一个人先用白色染一块矩形区域 第二个人再用黑色染一块矩形区域 问最后黑白格子各有多少个 思路:这题的关键在于求相交的矩形区间 给出一个矩形的左下和 ...
- 判断圆和矩形是否相交C - Rectangle and Circle
Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are p ...
- HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1221 Rectangle and Circle Time Limit: 2000/1000 MS (J ...
- poj1410(判断线段和矩形是否相交)
题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两 ...
- 计算几何--判断两条线段相交--poj 2653
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8862 Accepted: 3262 De ...
- TZOJ 2560 Geometric Shapes(判断多边形是否相交)
描述 While creating a customer logo, ACM uses graphical utilities to draw a picture that can later be ...
- Any Way You Slice It (向量旋转 以及 判断线段是否相交)(模板)
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11353 #include<iostream> # ...
- Jack Straws(判断线段是否相交 + 并查集)
/** http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1840 题意: 判断线段 ...
- hdu 1147:Pick-up sticks(基本题,判断两线段相交)
Pick-up sticks Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- 让tomcat启动时,自动加载你的项目
在tomcat-->conf-->serve.xml文件最后加上 <Context path="/atest" docBase="E:\Workspac ...
- MongoDB 项目集成 mongo-driver 3.4.2
第一次写技术!大白话讲讲.拿着用就可以了 本人是,NET的技术人员,会点JAVA所以很多不专业,见谅哈 刚刚开始使用mongo 整整搞了两天我才搞个半桶水,还是将就着用吧 随便把mongo在win的搭 ...
- BZOJ_4010_[HNOI2015]菜肴制作_拓扑排序+贪心
BZOJ_4010_[HNOI2015]菜肴制作_拓扑排序+贪心 Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为菜 ...
- C++之全局函数和成员函数互相转换
解析:成员函数会用this指针自动隐藏第一个操作数(左操作数) 1.把全局函数转化成成员函数,通过this指针隐藏左操作数. Test add(Test &t1,Test &t2) ...
- 洛谷P4719 动态DP —— 动态DP(树剖+矩乘)
题目:https://www.luogu.org/problemnew/show/P4719 感觉这篇博客写得挺好:https://blog.csdn.net/litble/article/detai ...
- JNI——JAVA调用C
1. 编译java:javac JNIDemo.java 2. 编译JNI:gcc -I/usr/lib/jvm/java-1.8.0-openjdk-amd64/include/ -I/usr/li ...
- Storm 1.0 新特性
Storm 1.0.0版本增加了很多新的特性,可用性以及性能也得到了很大的改善,该版本是Storm发展历程上一个里程碑式的版本,主要特点如下. 性能提升 Storm 1.0.0版本最大的亮点就是性能提 ...
- 深入Mybatis配置文件
Configuration是干嘛的 Configuration就像是Mybatis的总管,Mybatis的所有配置信息都存放在这里,此外,它还提供了设置这些配置信息的方法.Configuration可 ...
- Console Event Handling
http://www.codeproject.com/Articles/2357/Console-Event-Handling Console Event Handling Kumar Gaurav ...
- ECharts使用问题
Echarts官网上给的例子,在最后有一个分号. 使用ajax请求,在eval()转化时出现错误,原因就是因为多了一个分号