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. 

InputThe 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. 
OutputYour 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 <cstdio>
#include <cstring>
#include <iostream> using namespace std; bool mp[][]; int main()
{
int a,b,c,d;
memset(mp,,sizeof(mp));
while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
{
// 每一组结束,输出并更新
if(a< || b< || c< || d<)
{
int ans=;
for(int i=;i<=;++i)
{
for(int j=;j<=;++j)
{
if(mp[i][j])
{
++ans;
}
}
}
printf("%d\n",ans);
memset(mp,,sizeof(mp));
continue;
}
// 暴力覆盖
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)
{
mp[i][j]=true;
}
}
} return ;
}

D - Counting Squares的更多相关文章

  1. HDU 1264 Counting Squares(线段树求面积的并)

    Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. Counting Squares[HDU1264]

    Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)

    版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...

  4. HDU 1264 Counting Squares(模拟)

    题目链接 Problem Description Your input is a series of rectangles, one per line. Each rectangle is speci ...

  5. Counting Squares_hdu_1264(矩阵).java

    Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. tc 146 2 RectangularGrid(数学推导)

    SRM 146 2 500RectangularGrid Problem Statement Given the width and height of a rectangular grid, ret ...

  7. UVaLive 6602 Counting Lattice Squares (找规律)

    题意:给定一个n*m的矩阵,问你里面有几面积为奇数的正方形. 析:首先能知道的是,大的矩阵是包括小的矩阵的,而且面积为奇数,我们只要考虑恰好在边界上的正方形即可,画几个看看就知道了,如果是3*3的有3 ...

  8. UVALive 6602 Counting Lattice Squares

    给定一个n*m的网格,求面积为奇数的正方形有多少个. 首先是n*m个面积为1的,然后剩下的要么是边长为奇数,要么被这样一个奇数边长所包围. 原因如下: 对于一个边长不平行于坐标抽的正方形,其边长一定是 ...

  9. POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)

    来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS   Memory Limit: 65536 ...

随机推荐

  1. CCF_ 201512-3_画图

    直接模拟就行了,注意坐标系方向与平常数组不一样,填充操作用深搜和广搜都可以,这里用了广搜. #include<iostream> #include<cstdio> #inclu ...

  2. IPsecVPN:阿里云VPN网关和深信服防火墙打通公有云和公司内网

    简介 目前许多公司网络环境为混合云(私有云,IDC,公司内网融合)的状态,通过内网ip的访问使得工作更加方便,需求也更为迫切,而本文介绍的即是实现私有云和公司内网互通的一种方法,希望对有此需求的小伙伴 ...

  3. 深入JVM垃圾回收机制,值得你收藏

    JVM可以说是为了Java开发人员屏蔽了很多复杂性,让Java开发的变的更加简单,让开发人员更加关注业务而不必关心底层技术细节,这些复杂性包括内存管理,垃圾回收,跨平台等,今天我们主要看看JVM的垃圾 ...

  4. 实例探究Aspectj,解析SentinelResourceAspect

    为了学习SentinelResourceAspect,这篇文章里我用Aspectj实现一个AOP实例,一起来看下. Sentinel 提供了 @SentinelResource 注解用于定义资源,支持 ...

  5. Import This - The Zen of Python

    The Zen of Python -- by Tim Peters Beautiful is better than ugly.Explicit is better than implicit.Si ...

  6. [Effective Java 读书笔记] 第三章 对所有对象都通用的方法 第八 ---- 九条

    这一章主要讲解Object类中的方法, Object类是所有类的父类,所以它的方法也称得上是所有对象都通用的方法 第八条 覆盖equals时需要遵守的约定 Object中的equals实现,就是直接对 ...

  7. Python3(六) 面向对象

    一.类的定义 1. class Student():     name = ' ' #定义变量     age = 0     def print_file(self):     #定义函数      ...

  8. How to Convert a Class File to a Java File?

    What is a programming language? Before introducing compilation and decompilation, let's briefly intr ...

  9. 向C++之父Bjarne Stroustrup致敬

    2013-04-25 21:30 (分类:社会人生) 非常好的文章 C ++ 的 背 影                                     ——C++之父Bjarne Strou ...

  10. [Redis-CentOS7]Redis集合操作(四)

    SADD 集合添加 127.0.0.1:6379> SADD bbs discuz.net (integer) 1 127.0.0.1:6379> SADD bbs "tiany ...