小羞耻。
就写出来一题。啊呜呜呜。
而且后面几次都是如此...
哭唧唧。
G
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
G题其实很简单,两个矩形重叠面积求出来就可以,一开始枚举了所有重叠情况..大概有十几种..我还都写出来了。
然后仔细想了想,画了个草图...随手画了个草图之后就明白了。竖着的四条线,横着的四条线,重叠面积永远是中间那两条线
排个序就求出来了。ANSWER=重叠面积/两个矩形总面积-重叠面积
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#define MOD 10000000
using namespace std;
typedef long long LL;
long long quickpow(long long n, long long base) {
long long res = 1;
while(n) {
if(n & 1) {
res = res * base % MOD;
}
n >>= 1;
base = base * base % MOD;
}
return res;
}//¿ìËÙÃÝ
LL X[5];
LL Y[5];
int main()
{
int T;
LL x1,y1,w1,h1,x2,y2,w2,h2;
cin>>T;
LL s1,s2;
LL a,b;
double s;
while(T--)
{
cin>>x1>>y1>>w1>>h1;
cin>>x2>>y2>>w2>>h2;
if(x1+w1<=x2||x1>=x2+w2||y1+h1<=y2||y1>=y2+h2)
{
printf("0.00\n");
continue;
}
X[1]=x1;X[2]=x1+w1;X[3]=x2;X[4]=x2+w2;
Y[1]=y1;Y[2]=y1+h1;Y[3]=y2;Y[4]=y2+h2;
sort(X+1,X+1+4);
sort(Y+1,Y+1+4);
a=X[3]-X[2];
b=Y[3]-Y[2];
s1=w1*h1;
s2=w2*h2;
s=(double)(a*b)/(s1+s2-a*b);
printf("%.2lf\n",s);
}
}