有一个很明显的做法就是判断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. 打击判定 判断矩形是否相交的更多相关文章

  1. Codeforces Round #524 (Div. 2) C. Masha and two friends 几何:判断矩形是否相交以及相交矩形坐标

    题意 :给出一个初始的黑白相间的棋盘  有两个人  第一个人先用白色染一块矩形区域 第二个人再用黑色染一块矩形区域 问最后黑白格子各有多少个 思路:这题的关键在于求相交的矩形区间 给出一个矩形的左下和 ...

  2. 判断圆和矩形是否相交C - Rectangle and Circle

    Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are p ...

  3. HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1221 Rectangle and Circle Time Limit: 2000/1000 MS (J ...

  4. poj1410(判断线段和矩形是否相交)

    题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两 ...

  5. 计算几何--判断两条线段相交--poj 2653

    Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8862   Accepted: 3262 De ...

  6. TZOJ 2560 Geometric Shapes(判断多边形是否相交)

    描述 While creating a customer logo, ACM uses graphical utilities to draw a picture that can later be ...

  7. Any Way You Slice It (向量旋转 以及 判断线段是否相交)(模板)

    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11353 #include<iostream> # ...

  8. Jack Straws(判断线段是否相交 + 并查集)

    /** http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1840    题意:    判断线段 ...

  9. hdu 1147:Pick-up sticks(基本题,判断两线段相交)

    Pick-up sticks Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. BestCoder3 1001 Task schedule(hdu 4907) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4907 题目意思:给出工作表上的 n 个任务,第 i 个任务需要 ti 这么长的时间(持续时间是ti ~ ...

  2. socket即时聊天

    服务端 package com.luhan.text; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Gri ...

  3. JavaScript Constructors

    Understanding JavaScript Constructors It was: 1) This article is technically sound. JavaScript doesn ...

  4. Exception in thread “main” java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone.

    Exception in thread “main” java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecogn ...

  5. AQS共享锁应用之Semaphore原理

    我们调用Semaphore方法时,其实是在间接调用其内部类或AQS方法执行的.Semaphore类结构与ReetrantLock类相似,内部类Sync继承自AQS,然后其子类FairSync和NoFa ...

  6. 【Boost】boost库asio详解2——io_service::run函数无任务时退出的问题

    io_service::work类可以使io_service::run函数在没有任务的时候仍然不返回,直至work对象被销毁. void test_asio_nowork() { boost::asi ...

  7. ARM之工作模式

    前言            以下内容是个人学习之后的感悟,转载请注明出处~ ARM工作模式 ARM工作模式根据功能不同,可分为7类: User Mode:用户模式.操作系统的Task一般以这种模式执行 ...

  8. Game with Powers

    题意: 有1~n,n个数字,两个人轮流操作,每一次一个人可以拿一个数字$x$,之后$x, x^2, x^3....x^t$全都被删掉. 给定n,问最优策略下谁赢. 解法: 考虑SG函数,可以注意到题目 ...

  9. Spring boot实例

    代码下载http://pan.baidu.com/s/1c2aXLkc 密码:2joh 1.代码包规划 Application主类 package com.smart; import org.spri ...

  10. 1.6-1.8 HBase表的物理模型

    一.HBase 物理模型 1. 1.Table中的所有行都按照row key的字典序排列: 2.Table在行的方向上分割为多个Region: 3.Region按天小分割的,每个表开始只有一个regi ...