判断两个矩形的中心的距离
#include <iostream> using namespace std; int main() { int a{}, b{}, c{}, d{}, e{}, f{}, g{}, h{}; while (scanf("%d%d%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f, &g, &h) != EOF) { double x1 = (a + c) / 2.0, y1 = (b + d) / 2.0, x2 = (e + g) / 2.0, y2 = (f + h) / 2.0; double z1 = abs(x1 - x2), z2 = abs(y1 - y2); double c1 = (abs(c - a) + abs(e - g)) / 2.0, c2 = (abs(b - d) + abs(f - h)) / 2.0; if (z1 >= c1 || z2 >= c2) printf("no\n"); else printf("yes\n"); } }
判断两个矩形的中心的距离