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. sublime: javascript/css 的格式化

    Sublime Text 3 破解版 + 注册机 + 汉化包 + 教程 http://www.xiumu.org/note/sublime-text-3.shtml 1.sublime 如果控制菜单选 ...

  2. 【Pycharm使用者必看】自定义【光标快速定位到行尾】的按键

    1.问题描述 使用Pycharm写代码时,有很多比较方便的快捷键,比如:Shift+Enter快速切换到下一行, 但每次切换到多个括号外或者想移动到行尾,就必须按 End 键或者鼠标点击, 这样操作幅 ...

  3. SELinux 和 iptables 开启关闭

    SELinux 是 2.6 版本的 Linux 内核中提供的强制访问控制(MAC)系统.对于目前可用的 Linux安全模块来说,SELinux 是功能最全面,而且测试最充分的,它是在 20 年的 MA ...

  4. NAT 地址转换

    NAT功能        NAT不仅能解决了lP地址不足的问题,而且还能够有效地避免来自网络外部的攻击,隐藏并保护网络内部的计算机.1.宽带分享:这是 NAT 主机的最大功能.解决IP4地址短缺的问题 ...

  5. python pandas合并多个excel(xls和xlsx)文件(弹窗选择文件夹和保存文件)

    # python pandas合并多个excel(xls和xlsx)文件(弹窗选择文件夹和保存文件) import tkinter as tk from tkinter import filedial ...

  6. 代理模式-jdk动态代理

    IDB package com.bjpowernode.proxy; /** * 代理类和目标类都必须使用同一个接口. */ public interface IDB { int insert(); ...

  7. Maven 父子工程的一些细节

    Project,项目,也叫做工程. 父子工程中,子模块会自动继承父工程的资源.依赖,但子模块之间是独立的,不能直接访问彼此中的资源.类. 就是说我们可以把多个子模块都要用的资源.依赖提出来,放到父工程 ...

  8. yamlpy接口测试框架

    1.思路: yamlpy即为yaml文件+pytest单元测试框架的缩写, 可以看作是一个脚手架工具, 可以快速生成项目的各个目录与文件, 只需维护一份或者多份yaml文件即可, 不需要大量写代码. ...

  9. 在window上安装mysql - MySQL5.7.24 版本

    1.下载安装包 下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 点击Download,选择 No thanks, just ...

  10. udp socket 10054

    udp socket 10054 在接收端没有启动的情况下 1.直接ReceiveFrom没问题. 2.如果先SendTo再ReceiveFrom,SendTo可以正常过,但是RecieveFrom会 ...