poj 1468 Rectangles

本文介绍了一种通过编程解决矩形覆盖问题的方法。利用C++实现了一个名为Rec的类来表示矩形,并定义了一个判断函数来检查一个矩形是否完全包含另一个矩形。通过对输入的多个矩形进行两两比较,统计出被其他矩形完全覆盖的矩形数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

水题,直接暴力:

View Code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#include<vector>
#include<string>
#define LL long long
using namespace std;
class Rec
{
public:
      double x1,y1,x2,y2;
}p[5024];
bool judge( Rec a, Rec b )
{
    if( b.x1<=a.x1 && b.x2>=a.x2 )
        if( b.y1 <= a.y1 && b.y2 >= a.y2 )
            return true;
    return false;
}
int Solve( int n )
{
    int sum = 0;
    for( int i = 0 ; i < n ; i ++ )
    {
        for( int j = 0 ; j < n ; j ++ )
        {
            if( j != i && judge( p[i],p[j] ))
            {
                sum ++;
                break;
           }
        }    
    }
    return sum;
}
int main(  )
{
    int n;
    while( scanf( "%d",&n )==1 )
    {
         for( int i = 0 ; i < n ; i ++ )
         {
             scanf( "%lf%lf%lf%lf",&p[i].x1,&p[i].x2,&p[i].y1,&p[i].y2 );        
         }    
         printf( "%d\n",Solve( n ) );
    }
    //system( "pause" );
    return 0;
}

转载于:https://www.cnblogs.com/bo-tao/archive/2012/07/30/2615049.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值