1468 Rectangles

Rectangles
Time Limit: 5000MS Memory Limit: 10000K
Total Submissions: 1187 Accepted: 586

Description
A specialist in VLSI design testing must decide if there are some components that cover each other for a given design. A component is represented as a rectangle. Assume that each rectangle is rectilinearly oriented (sides parallel to the x and y axis), so that the representation of a rectangle consists of its minimum and maximum x and y coordinates.
Write a program that counts the rectangles that are entirely covered by another rectangle.

Input
The input contains the text description of several sets of rectangles. The specification of a set consists of the number of rectangles in the set and the list of rectangles given by the minimum and maximum x and y coordinates separated by white spaces, in the format:

nr_rectangles
xmin1 xmax1 ymin1 ymax1
xmin2 xmax2 ymin2 ymax2
...
xminn xmaxn yminn ymaxn

For each set,there will be less than 5000 rectangles.

Output
The output should be printed on the standard output. For each given input data set, print one integer number in a single line that gives the result (the number of rectangles that are covered).

Sample Input

 

Sample Output

 

Source
Southeastern Europe 2000

 *******************************************************************************

***********************************************************************************

  • Source Code
    现根据面积,选出面积最大的,并插入排序 并保存原始的数据下标!!!!再搜索一下符合条件的
    
    #include <iostream>
    using namespace std;
    
    struct Rectangle
    {
    int minx;
    int maxx;
    int miny;
    int maxy;
    };
    
    int main()
    {
    int Area[5000],Area1[5000],a[5000];
    Rectangle Rec[5000];
    int i ,j ,temp ;
    int num, Index ,sum;
    while(scanf("%d",&num )!=EOF )
    {
       for(i=0; i<num; i++)
       {
        scanf("%d %d %d %d", &Rec[i].minx, &Rec[i].maxx, &Rec[i].miny, &Rec[i].maxy );
        Area[i] = ( Rec[i].maxx - Rec[i].minx ) *( Rec[i].maxy-Rec[i].miny);
        Area1[i] =Area[i];
       }
    
            for(i=0;i<num-1;i++)
         {
               int   min=i;
               for(j = i+1; j < num; j ++)
                 if( Area1[j] < Area1[min])
                    min = j;
               temp = Area1[min];
               Area1[min] = Area1[i];
               Area1[i] = temp;
         }
         for(i = 0; i < num; i ++)
               for(j=0 ; j < num; j ++)
                 if(Area1[i] == Area[j])
                 {
                    Area[j]=0;
                    a[i]=j;
                    break;
        }
            for(sum=0,j=0;j<num-1;j++)
              for(i=j+1;i<num;i++)
                if(Rec[a[j]].maxx<=Rec[a[i]].maxx&&Rec[a[j]].minx>=Rec[a[i]].minx
          &&Rec[a[j]].maxy<=Rec[a[i]].maxy&&Rec[a[j]].miny>=Rec[a[i]].miny )
                {     
                   sum++;
                   break;
         }     
            for(i=0;i<num-1;i++)
               if(Rec[i].maxx==Rec[num-1].maxx && Rec[i].minx==Rec[num-1].minx
         &&Rec[i].maxy==Rec[num-1].maxy&&Rec[i].miny==Rec[num-1].miny)
               {
                  sum+=1;
                  break;
               }
    
       printf("%d/n",sum);
    }
    return 0;
    }
    

     

    0
    4

     

    3
    100 101 100 101
    0 3 0 101
    20 40 10 400
    4
    10 20 10 20
    10 20 10 20
    10 20 10 20
    10 20 10 20
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xcl119xxcl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值