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. wordpress 如何正确升级

    http://www.admin5.com/article/20141230/578710.shtml 正确的版本升级应该是,备份数据库和文件,然后禁用所有的插件后在执行升级.这样也避免不了升级过后启 ...

  2. 什么是伪静态,以及ubuntu + apache 如何实现伪静态

    原文链接:http://www.cnblogs.com/ainiaa/archive/2010/07/25/1784564.html php伪静态 一直在做php的开发工作.在开发的过程中老早就听说了 ...

  3. LaTeX技巧472:定义一个LaTeX参考文献不带编号且有缩进的方法

    LaTeX_Fun的博客 LaTeX技巧381:参考文献项第二行缩进如何定义? \makeatletter\renewenvironment{thebibliography}[1]{\section* ...

  4. ELK:收集k8s容器日志最佳实践

    简介 关于日志收集这个主题,这已经是第三篇了,为什么一再研究这个课题,因为这个课题实在太重要,而当今优秀的开源解决方案还不是很明朗: 就docker微服务化而言,研发有需求标准输出,也有需求文件输出, ...

  5. Go语言实现:【剑指offer】旋转数组的最小数字

    该题目来源于牛客网<剑指offer>专题. 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3, ...

  6. 用Java反射输出对象的所有属性的值

    获取对象的类类型 Class cls = obj.getClass(); 用类类型获取属性数组 getFields()获取的是共有属性 getDeclaredFields()可以获取所有属性 Fiel ...

  7. k8s系列---service

    来源 : http://blog.itpub.net/28916011/viewspace-2214745/ service是要通过coreDNS来管理pod的. kube-proxy始终监视着api ...

  8. light oj1028 - Trailing Zeroes (I)

    1028 - Trailing Zeroes (I)   We know what a base of a number is and what the properties are. For exa ...

  9. OpenCV3入门(十)图像轮廓

    1.图像轮廓 1.1图像轮廓与API函数 轮廓是一系列相连的点组成的曲线,代表了物体的基本外形,相对于边缘,轮廓是连续的,边缘并不全部连续.一般地,获取图像轮廓要经过下面几个步骤: 1)     读取 ...

  10. Sap Hana 关于BP的一些理解

    BP里面有角色和角色分组,角色分组相当于包含多个角色. 客户和供应商使用不同的角色来创建. 创建角色和分组前可以创建自定义的角色类别和角色分组类别. 文档:关于BP.note 链接:笔记 作者:明光烁 ...