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 ...
随机推荐
- winform应用如何发布(不用打包)、并提醒用户自动更新
环境:VS2019 community C# winform 应用程序 设计应用程序界面 编写对应代码 使用PS设计程序标识ICON F4打开属性: 设置ICON 设置背景 打开项目属性 打开“发 ...
- Codeforces 977B Two-gram(stl之string掉进坑)
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, " ...
- java9循环结构进阶
public class jh_01_循环嵌套 { public static void main(String[] args) { // for(int i = 1;i<= 5;i++) { ...
- 为什么用上了HTTPS,还是被流量劫持?
广告再临 “老周,有人找你” 一大早,361杀毒公司的老周就被吵醒. 今天的阳光很明媚,老周伸了伸懒腰,这才踱步走向工作室. “是谁一大早的就来吵吵,坏了我的瞌睡”,听得出来,老周有点不太高兴. “咚 ...
- jQuery 基础 (笔记源于runoob)
您需要具备的基础知识 在您开始学习 jQuery 之前,您应该对以下知识有基本的了解: HTML CSS JavaScript jQuery ? jQuery是一个JavaScript函数库. jQu ...
- python学习(10)字典学习,写一个三级菜单程序
学习了字典的应用.按老师的要求写一个三级菜单程序. 三级菜单程序需求如下: 1.深圳市的区--街道--社区---小区4级 2.建立一个字典,把各级区域都装进字典里 3.用户可以从1级进入2级再进入3级 ...
- One Stage目标检测
在计算机视觉中,目标检测是一个难题.在大型项目中,首先需要先进行目标检测,得到对应类别和坐标后,才进行之后的各种分析.如人脸识别,通常是首先人脸检测,得到人脸的目标框,再对此目标框进行人脸识别.如果该 ...
- Maven项目pom文件的节点释意
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- [Redis-CentOS7]Redis数据持久化(八)
配置文件位置 /ect/redis.conf RDB存储配置 save 900 1 # 900秒之内发生一次写操作保存 save 300 10 # 300秒内写10次保存 save 60 10000 ...
- Cobalt Strike生成后门
Cobalt Strike生成后门 1.Payload概念 Payload在渗透测试之中大家可以简单地理解为一段漏洞利用/植入后门的代码或程序. 2.Cobalt Strike生成后门 攻击--> ...