首页 > 代码库 > UVa 10703 - Free spots

UVa 10703 - Free spots

题目:给定一个矩形点集,从里面扣掉一些小矩形点集,问最后还有多少个点。

分析:简单题。由于数据较小,暴力就可以了,数据大时,可使用线段树。

说明:

#include <algorithm>  
#include <iostream> 
#include <cstring>
#include <cstdio>
  
using namespace std;  

bool maps[505][505];  
  
int main()  
{  
    int w, h, n, x1, y1, x2, y2;  
  	
    while (~scanf("%d%d%d",&w,&h,&n) && w) {  
		
        memset(maps, true, sizeof(maps));
        
        for (int i = 0; i < n ; ++ i) {
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);  
            
            if (x1 > x2) swap(x1, x2);  
            if (y1 > y2) swap(y1, y2); 
			 
            for (int j = x1; j <= x2 ; ++ j)
            for (int k = y1; k <= y2 ; ++ k)  
                maps[j][k] = 0;  
        }  
  
        int ans = 0;  
        for (int i = 1; i <= w ; ++ i)  
        for (int j = 1; j <= h ; ++ j) 
            if(maps[i][j])
				ans ++;  

        if (ans == 0)  
            printf("There is no empty spots.\n");  
        else if (ans == 1)  
            printf("There is one empty spot.\n");  
        else  
            printf("There are %d empty spots.\n",ans);  
    }
    return 0;  
}



UVa 10703 - Free spots