BASIC-18 VIP试题 矩形面积交

  • 排序横纵坐标判断是否相交
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int N=5;
const int M=2e5+9;
#define gt getchar();
#define line '\n'
#define is isdigit
int read(){int x=0,op=1;char c=gt;while(!is(c)){if(c=='-')op=-1;c=gt;}while(is(c))x=x*10+c-48,c=gt;return x*op;}
double x[N],y[N];
int main()
{
	for(int i=1;i<=4;++i)cin>>x[i]>>y[i];
	sort(x+1,x+3),sort(x+3,x+5);
	sort(y+1,y+3),sort(y+3,y+5);
	if(x[1]>=x[4]||x[2]<=x[3]||y[1]>=y[4]||y[2]<=y[3]){
		cout<<"0.00"<<line;
		return 0;
	}
	sort(x+1,x+5),sort(y+1,y+5);
	cout<<fixed<<setprecision(2)<<(x[3]-x[2])*(y[3]-y[2])<<line;
	return 0;
}
上一篇:BASIC-4 数列特征


下一篇:如何做一个消息轰炸机