D - Counting Squares
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的更多相关文章
- HDU 1264 Counting Squares(线段树求面积的并)
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Counting Squares[HDU1264]
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)
版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...
- HDU 1264 Counting Squares(模拟)
题目链接 Problem Description Your input is a series of rectangles, one per line. Each rectangle is speci ...
- Counting Squares_hdu_1264(矩阵).java
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- tc 146 2 RectangularGrid(数学推导)
SRM 146 2 500RectangularGrid Problem Statement Given the width and height of a rectangular grid, ret ...
- UVaLive 6602 Counting Lattice Squares (找规律)
题意:给定一个n*m的矩阵,问你里面有几面积为奇数的正方形. 析:首先能知道的是,大的矩阵是包括小的矩阵的,而且面积为奇数,我们只要考虑恰好在边界上的正方形即可,画几个看看就知道了,如果是3*3的有3 ...
- UVALive 6602 Counting Lattice Squares
给定一个n*m的网格,求面积为奇数的正方形有多少个. 首先是n*m个面积为1的,然后剩下的要么是边长为奇数,要么被这样一个奇数边长所包围. 原因如下: 对于一个边长不平行于坐标抽的正方形,其边长一定是 ...
- POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536 ...
随机推荐
- PHP反序列化中过滤函数使用不当导致的对象注入
1.漏洞产生的原因 #### 正常的反序列化语句是这样的 $a='a:2:{s:8:"username";s:7:"dimpl3s";s:8:"pa ...
- Codeforces_490_E
http://codeforces.com/problemset/problem/490/E dfs,过程要注意细节,特别是当前位置取了与上个数当前位置相同是,若后面不符合条件,则当前位置要重置'?' ...
- php 关于php创建 json文件 和 对文件增删改查 示例
<?php //fopen($file,'w'); //打开文件/创建文件 //file_put_contents($file,$content)//写入文件 //file_get_conten ...
- ORB-SLAM2 论文&代码学习 —— 概览
转载请注明出处,谢谢 原创作者:MingruiYU 原创链接:https://www.cnblogs.com/MingruiYu/p/12347171.html *** 本文要点: ORB-SLAM2 ...
- logstash 配置文件语法
需要一个配置文件 管理输入.过滤器和输出相关的配置.配置文件内容格式如下: # 输入 input { ... } # 过滤器 filter { ... } # 输出 output { ... } 先来 ...
- day14 jQuery
day13-14 jQueryjQuery是对js和dom的封装,相当于一个类库使用jQuery的目的: 1:获取标签 2:修改jQuery提供的方法:http://www.php100.com/ma ...
- windows下修改tomcat的startup.bat脚本文件后台运行
1.修改startup.bat文件 rem Get remaining unshifted command line arguments and save them in the set CMD_LI ...
- C语言基础二 练习
指出正确标识符 命名 l 只能由26个英文字母的大小写.10个阿拉伯数字0~9.下划线_组成 l 严格区分大小写,比如test和Test是2个不同的标识符 l 不能以数字开头 l 不可以使用关键字作为 ...
- console控制台的用法
参考链接:https://developer.mozilla.org/zh-CN/docs/Web/API/Console 1,console.log('a'); 2,console.dir(xx); ...
- 深入源码分析SpringMVC执行过程
本文主要讲解 SpringMVC 执行过程,并针对相关源码进行解析. 首先,让我们从 Spring MVC 的四大组件:前端控制器(DispatcherServlet).处理器映射器(HandlerM ...