题目链接

Problem Description
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

题解:水题,因为数字范围不大,可以用二维数组保存每个1x1的块是否被访问过。

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#define PI acos(-1.0)
#define ms(a) memset(a,0,sizeof(a))
#define msp memset(mp,0,sizeof(mp))
#define msv memset(vis,0,sizeof(vis))
using namespace std;
//#define LOCAL
int mp[][];
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
int x1,y1,x2,y2;
int cnt=;
msp;
while(cin>>x1>>y1>>x2>>y2)
{
if(x1==-){printf("%d\n",cnt);
msp,cnt=;}
if(x1==-){
printf("%d\n",cnt);break;}
if(x1>x2)swap(x1,x2);
if(y1>y2)swap(y1,y2);
for(int i=x1;i<x2;i++)
for(int j=y1;j<y2;j++)
if(mp[i][j])continue;
else {cnt++,mp[i][j]=;}
}
return ;
}

HDU 1264 Counting Squares(模拟)的更多相关文章

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

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

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

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

  3. hdu 5862 Counting Intersections

    传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...

  4. Counting Squares[HDU1264]

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

  5. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  6. [hdu 6184 Counting Stars(三元环计数)

    hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...

  7. Hdu 5862 Counting Intersections(有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点+树状数组区间求和单点跟新)

    传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的 ...

  8. HDU 5510---Bazinga(指针模拟)

    题目链接 http://acm.hdu.edu.cn/search.php?action=listproblem Problem Description Ladies and gentlemen, p ...

  9. HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...

随机推荐

  1. 标准I/O 缓存

    标准I/O提供了三种类型的缓存: (1)全缓存.在这种情况下,当填满标准I/O 缓存后才进行实际 I/O 操作.对于驻在磁盘上的文件通常是由标准I/O库实施全缓存的.在一个流上执行第一次I/O操作时, ...

  2. C语言课程设计 Win32应用程序

    问题描述: 请设计一个职工信息管理程序,以方便人事部门对本单位职工的管理,该程序应该具有以下功 能: (1)能从键盘输入职工的信息 . (2)给定职工号,显示职工的信息. (3)给定工作部门,显示该部 ...

  3. MAC OS U 盘制作与安装方法

    伴随着 iMac 5K Retina 和新的 Mac mini 等硬件的发布,苹果终于都推出了 OS X Yosemite 系统正式版了!相信很多人都已经用上.不过对于一些不想升级,而是打算「全新安装 ...

  4. datagridview自绘

    https://msdn.microsoft.com/zh-cn/library/85kxk29c(v=vs.85).aspx 以上效果实现代码如下,细节部分就由你完善了,这里只是写个小例子: usi ...

  5. SVN版本控制的使用

    下面说一说本人对SVN工具使用的理解: SVN就是一个工具,一个用来便于多人(或说团队)开发代码的版本控制工具,我们可以用它很好的把多个程序员开发出来的代码统一起来,并且保证在这个工程中不出现任何差错 ...

  6. mysql的数据类型与列属性

  7. Fiddler的安装设置

    一.安装设置Fiddler2  下载完成后安装,安装完成后打开 如下图设置Fiddler 代理: 二.设置手机代理 快捷键win+r打开运行窗口à输入:cmdà确定 在界面上输入:ipconfig,查 ...

  8. Python学习笔记——基础篇【第五周】——正则表达式(re)

    目录 1.简介 2.字符匹配 1.简介:就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译 ...

  9. 最有用的Gulp插件汇总

    HTML&CSS autoprefixer - parse CSS and add vendor prefixes to rules by Can I Use. gulp-browser-sy ...

  10. 关于css3的fixed布局

    理解CSS3里的Flex布局用法 2016-10-21 阮一峰 web前端开发 web前端开发 web前端开发 微信号 web_qdkf 功能介绍 我们专注web前端开发技术的学习(html,css, ...