codeforces 993 A
introduction
判断两个正方形是否相交(只有一个有公共点也算相交),其中一个平放,另一个倾斜45°。
method
方法有很多,从直观上都可以理解。但我的方法太麻烦了,失败了。
觉得题解的思路很好,所以记录一下。
为了便于描述,平放的正方形记为
A,倾斜
45°的记为
B 相交可以分为4种情况:
- B的角落在A中
- A的角落在B中
- B的中心落在A中
- A的中心落在B中
第一种情况好判断,按照是两个平放的正方形来处理。难点是A在B中的情况。
一个想法是将
A旋转
45°,
B也旋转
45°,这样就转化成第一种情况。但是这样做的代价是引入了浮点数。题解的巧妙之处就是观察到了放缩是不会改变相交性的。
replace each ? coordinate with ?+? and each ? coordinate with ?−?
这样就完全转化成第一种情况
其他的思路
点都是整点,并且每个正方形最多是
100×100,可以枚举两个正方形是否有公共点
tips
- 放缩是不会改变相交性的
- 两个平放正方形的相交性
reference
code
#include #include #include #include #include #include #include #include #include