蓝桥训练 - 求两矩形面积交

思路:给的是对角坐标 不一定左下右上 所以要处理一下
之前做过 还好做过 不然又大模拟了- -
还有max min函数最好自己定义- -

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define MID (t[k].l+t[k].r)>>1
#define cl(a,b) memset(a,b,sizeof(a))
#define dbg() printf("aaa\n")
using namespace std;
double _min(double a,double b){
	if(a<b) return a;
	return b; 
}
double _max(double a,double b){
	if(a>b) return a;
	return b;
}
int main() {
	double a,b,c,d,e,f,g,h;
    cin>>a>>b>>c>>d>>e>>f>>g>>h;
    //先变成左下右上
    double a2=_min(a,c);
    double c2=_max(a,c);
    double b2=_min(b,d);
    double d2=_max(b,d);
    double e2=_min(e,g);
    double g2=_max(e,g);
    double f2=_min(f,h);
    double h2=_max(f,h);
    if(c2<=e2||d2<=f2||a2>=g2||b2>=h2){
        printf("0.00\n");
    }else{
        printf("%.2lf\n",(_min(c2,g2)-_max(a2,e2))*(_min(d2,h2)-_max(b2,f2)));
    }

	return 0;
}
发布了120 篇原创文章 · 获赞 12 · 访问量 5281

猜你喜欢

转载自blog.csdn.net/weixin_43735161/article/details/104558381