hdu 1264 Counting Squares

传送门

Your input is a series of rectangles, one per line. Each rectangle is specified as two points(X,Y) that specify the opposite corners of a rectangle. All coordinates will be integers in the range 0 to 100. For example, the line
5 8 7 10
specifies the rectangle who's corners are(5,8),(7,8),(7,10),(5,10).
If drawn on graph paper, that rectangle would cover four squares. Your job is to count the number of unit(i.e.,1*1) squares that are covered by any one of the rectangles given as input. Any square covered by more than one rectangle should only be counted once.

Input

The input format is a series of lines, each containing 4 integers. Four -1's are used to separate problems, and four -2's are used to end the last problem. Otherwise, the numbers are the x-ycoordinates of two points that are opposite corners of a rectangle.

Output

Your output should be the number of squares covered by each set of rectangles. Each number should be printed on a separate line.

Sample Input

5 8 7 10
6 9 7 8
6 8 8 11
-1 -1 -1 -1
0 0 100 100
50 75 12 90
39 42 57 73
-2 -2 -2 -2

Sample Output

8
10000

【题意】

给你一些矩形,然后问你被矩形覆盖至少一次的面积。重复覆盖的地方只统计一次。

【分析】

直接暴力模拟就行了,然后统计哪些点被覆盖过就行了,因为数据量实在是小。

【代码】

#include<bits/stdc++.h>
using namespace  std;
bool mat[105][105];
int ans()
{
    int ret = 0;
    for(int i = 0;i<105;i++) for(int j = 0;j<105;j++)
        if(mat[i][j]) ret++;
    return ret;
}
int main()
{
    int a,b,c,d;
    memset(mat,false,sizeof(mat));
    while(cin>>a>>b>>c>>d)
    {

        if(a<0)
        {
            cout<< ans() <<endl;
            memset(mat,false,sizeof(mat));
            if(a==-2) break;
        }
        else
        {
            if(a>c) swap(a,c);
            if(b>d) swap(b,d);
            for(int i = a;i<c;i++)
                for(int j = b;j<d;j++)
                    mat[i][j] = true;
        }
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

zuhiul

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

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

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

打赏作者

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

抵扣说明:

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

余额充值