FZU - 2300
Xzz need to calculate Intersection over Union(IoU) of two rectangles, can you help him?
rectangle (x, y, w, h) means a rectangle MNPQ, M(x,y), N(x, y+h), P(x+w, y+h), Q(x+w, y).
IoU = Area of overlap / Area of union.
Input
First line of the input file contains an integer T(0 < T <= 100) that indicates how many cases of inputs are there.
The description of each case is given below:
The first line of each input set contains integer x1, y1, w1, h1.
The second line of each input set contains integer x2, y2, w2, h2.
0 ≤ x, y, w, h ≤ 100000
Output
The description of output for each test case is given below:
The first line of the output for each test case contains number k- the IoU of two rectangles.
Output should be rounded to 2 digits after decimal point.
Sample Input
2 1 1 1 1 1 1 2 2 1 1 2 1 1 1 1 2
Sample Output
0.25 0.33
先输入一个整数t,代表有t组测试,对于每组测试,输入两行,每行四个整数x,y,dx,dy,代表矩形的左下角的坐标以及它的长和宽,问这两个矩形的重合面积/这两个矩形组成的区域的面积是多少。
直接求解即可,需要判断一下不重合的情况。
#include
#include
#include
#include
#include
#include
#include