UESTC 2018 Summer Training #3 Div.2 G

小羞耻。

就写出来一题。啊呜呜呜。

而且后面几次都是如此...

哭唧唧。

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);
    }
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值