hdu6665 Calabash and Landlord 杭电多校第8场

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6665

比赛中分情况讨论没过,队友用离散化跑dfs过了,十分精妙

赛后把情况讨论分对了,判断完全在外部的情况,相等的情况,两条对边有重合的情况,一个内含另一个但只可能相邻边重合的情况,其他剩下的相交的情况就都是4了。

#include<bits/stdc++.h>

using namespace std;

int ans;
struct node
{
    int x1,y1,x2,y2;
}a,b;

inline void prework()
{
    scanf("%d%d%d%d",&a.x1,&a.y1,&a.x2,&a.y2);
    scanf("%d%d%d%d",&b.x1,&b.y1,&b.x2,&b.y2);
}

inline void mainwork()
{
    if(b.x2<=a.x1 || b.x1>=a.x2 || b.y2<=a.y1 || b.y1>=a.y2)//完全在外部 
    {
        ans=3;
        return;
    }
    if(a.x1==b.x1 && a.x2==b.x2 && a.y1==b.y1 && a.y2==b.y2)//相等 
    {
        ans=2;
        return;
    }
    if(a.x1==b.x1 && a.x2==b.x2)    // 两条对边有重合部分 
    {
        if(b.y1==a.y1 || b.y2==a.y2)
        {
            ans=3;
            return;
        }
        else
        {
            ans=4;
            return;
        }
    }
    if(a.y1==b.y1 && a.y2==b.y2) // 两条对边有重合部分 
    {
        if(b.x1==a.x1 || b.x2==a.x2)
        {
            ans=3;
            return;
        }
        else
        {
            ans=4;
            return;
        }
    }
    if(b.x1<=a.x1 && b.x2>=a.x2 && b.y1<=a.y1 && b.y2>=a.y2)//内涵且只有相邻边重合 
    {
        ans=3;
        return;
    }
    if(b.x1>=a.x1 && b.x2<=a.x2 && b.y1>=a.y1 && b.y2<=a.y2)//内涵且只有相邻边重合
    {
        ans=3;
        return;
    }
    if(b.x1>=a.x1 && b.x2<=a.x2)//夹在中间 
    {
        if(b.y1<=a.y1 && b.y2>=a.y2)
        {
        	if(b.x1==a.x1 || b.x2==a.x2)
        		ans=3;
        	else	
        		ans=4;
        	if(b.y1<a.y1)
        		ans++;
        	if(b.y2>a.y2)
        		ans++;
		}
		else
			ans=4;
        return;
    } 
    if(b.y1>=a.y1 && b.y2<=a.y2)//夹在中间 
    {
        if(b.x1<=a.x1 && b.x2>=a.x2)
		{
			if(b.y1==a.y1 || b.y2==a.y2)
				ans=3;
			else
				ans=4;
			if(b.x1<a.x1)
				ans++;
			if(b.x2>a.x2)
				ans++;
		} 
		else
			ans=4;
        return;
    }
    ans=4;
}

inline void print()
{
    printf("%d\n",ans);
}

int main()
{
	//freopen("i.in","r",stdin);
	//freopen("i.out","w",stdout); 
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        prework();
        mainwork();
        print();
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值