2019杭电暑期多校第八场 I:Calabash and Landlord(分类讨论)

【题解】

2019杭电暑期多校第八场 I:Calabash and Landlord(分类讨论)_第1张图片

【代码】

#include
using namespace std;
#define ll long long
const int maxn=1e5+10;
bool check(ll x1,ll y1,ll x2,ll y2,ll x3,ll y3,ll x4,ll y4)
{
    return x1<=x3&&y1<=y3&&x2>=x4&&y2>=y4;
}
bool check1(ll x1,ll y1,ll x2,ll y2,ll x3,ll y3,ll x4,ll y4)
{
    return x1y3&&x2>x4&&y2y3&&x2>x4&&y2x4&&y2y3&&x2==x4&&y2y3&&x2>x4&&y2==y4);
}
int main()
{
    int t; scanf("%d",&t);
    while(t--){
        ll x1,y1,x2,y2;
        ll x3,y3,x4,y4;
        scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
        scanf("%lld%lld%lld%lld",&x3,&y3,&x4,&y4);
        int ans;
        if(x1==x3&&y1==y3&&x2==x4&&y2==y4){ //相同
            ans=2;
        }
        else if(x2<=x3||y2<=y3||x4<=x1||y4<=y1){ //相离
            ans=3;
        }
        else if(check(x1,y1,x2,y2,x3,y3,x4,y4)||check(x3,y3,x4,y4,x1,y1,x2,y2)){ //包含
            if((x1==x3&&x2==x4&&y1!=y3&&y2!=y4)||(x1!=x3&&x2!=x4&&y1==y3&&y2==y4))
                ans=4;
            else ans=3;
        }
        else{ //相交
            if(check1(x1,y1,x2,y2,x3,y3,x4,y4)||check1(x3,y3,x4,y4,x1,y1,x2,y2))
                ans=6;
            else if(check2(x1,y1,x2,y2,x3,y3,x4,y4)||check2(x3,y3,x4,y4,x1,y1,x2,y2))
                ans=5;
            else ans=4;
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

你可能感兴趣的:(2019杭电暑期多校第八场 I:Calabash and Landlord(分类讨论))