Shaping Regions

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 124  Solved: 39
[Submit][Status][Web Board]

Description

N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the sheet's borders. All rectangles fall within the borders of the sheet so that different figures of different colors will be seen.

The coordinate system has its origin (0,0) at the sheet's lower left corner with axes parallel to the sheet's borders.

Input

This problem includes multiple cases. The first line of input is a integer T represents the number of cases. 
For each case: The order of the input lines dictates the order of laying down the rectangles. The first input line is a rectangle "on the bottom".
Line 1: A, B, and N, space separated (1 <= A,B <= 10,000)
Lines 2-N+1: Five integers: llx, lly, urx, ury, color: the lower left coordinates and upper right coordinates of the rectangle whose color is `color' (1 <= color <= 2500) to be placed on the white sheet. The color 1 is the same color of white as the sheet upon which the rectangles are placed.

Output

For each case, output corresponding results separately.
The output of each case should contain a list of all the colors that can be seen along with the total area of each color that can be seen (even if the regions of color are disjoint), ordered by increasing color. Do not display colors with no area.

Sample Input

1
20 20 3
2 2 18 18 2
0 8 19 19 3
8 0 10 19 4

Sample Output

1 91
2 84
3 187
4 38

HINT

Note that the rectangle delineated by 0,0 and 2,2 is two units wide and two high. Here's a schematic diagram of the input:

11111111111111111111

33333333443333333331

33333333443333333331

33333333443333333331

33333333443333333331

33333333443333333331

33333333443333333331

33333333443333333331

33333333443333333331

33333333443333333331

33333333443333333331

33333333443333333331

11222222442222222211

11222222442222222211

11222222442222222211

11222222442222222211

11222222442222222211

11222222442222222211

11111111441111111111

11111111441111111111

The '4's at 8,0 to 10,19 are only two wide, not three (i.e., the grid contains a 4 and 8,0 and a 4 and 8,1 but NOT a 4 and 8,2 since this diagram can't capture what would be shown on graph paper).

在矩形中涂色覆盖问每种颜色最后有多少块

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define ls 2*i
#define rs 2*i+1
#define up(i,x,y) for(i=x;i<=y;i++)
#define down(i,x,y) for(i=x;i>=y;i--)
#define mem(a,x) memset(a,x,sizeof(a))
#define w(a) while(a)
#define LL long long
const double pi = acos(-1.0);
#define Len 200005
#define mod 19999997
const int INF = 0x3f3f3f3f;
#define exp 1e-6
int seq[][];
int col[],col_num[];
int A,B;
int n;
long long dfs(int begin,int a,int b,int c,int d)
{
if(a >= c || b >= d) return ;
for(int i = begin; i <= n; i++)
{
int x1=seq[i][],y1=seq[i][],x2=seq[i][],y2=seq[i][];
if(! (a>=x2 || b>=y2 || c<=x1 || d<=y1) )
{
if(a < x1 && c > x1)
{
return dfs(i, a, b, x1, d)+dfs(i, x1, b, c, d);
}
else if(a < x2 && c > x2)
{
return dfs(i, a, b,x2, d) + dfs(i,x2, b, c, d);
}
else
return dfs(i, a, b, c, y1) + dfs(i, a,y2, c, d);
}
}
return ((c - a) * (d - b));
}
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
scanf("%d%d%d",&A,&B,&n);
seq[][] = seq[][] = ;
seq[][] = A,seq[][] =B,col[] = ;
for(int i = ; i <= n; i++)
{
scanf("%d%d%d%d%d",&seq[i][],&seq[i][],&seq[i][],&seq[i][],&col[i]);
}
memset(col_num, ,sizeof(col_num));
for(int i = n; i >= ; i--)
{
col_num[col[i]] += dfs(i+,seq[i][],seq[i][],seq[i][],seq[i][]);
}
for(int i = ; i <= ; i++)
{
if(col_num[i] > )
printf("%d %d\n",i,col_num[i]);
} }
return ; } /**************************************************************
Problem: 1589
User: aking2015
Language: C++
Result: Accepted
Time:16 ms
Memory:1516 kb
****************************************************************/

Shaping Regions(dfs)的更多相关文章

  1. Leetcode之深度优先搜索(DFS)专题-130. 被围绕的区域(Surrounded Regions)

    Leetcode之深度优先搜索(DFS)专题-130. 被围绕的区域(Surrounded Regions) 深度优先搜索的解题详细介绍,点击 给定一个二维的矩阵,包含 'X' 和 'O'(字母 O) ...

  2. Leetcode之深度优先搜索(DFS)专题-200. 岛屿数量(Number of Islands)

    Leetcode之深度优先搜索(DFS)专题-200. 岛屿数量(Number of Islands) 深度优先搜索的解题详细介绍,点击 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计 ...

  3. LeetCode Subsets II (DFS)

    题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...

  4. LeetCode Subsets (DFS)

    题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...

  5. HDU 2553 N皇后问题(dfs)

    N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 在 ...

  6. 深搜(DFS)广搜(BFS)详解

    图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...

  7. 【算法导论】图的深度优先搜索遍历(DFS)

    关于图的存储在上一篇文章中已经讲述,在这里不在赘述.下面我们介绍图的深度优先搜索遍历(DFS). 深度优先搜索遍历实在访问了顶点vi后,访问vi的一个邻接点vj:访问vj之后,又访问vj的一个邻接点, ...

  8. 深度优先搜索(DFS)与广度优先搜索(BFS)的Java实现

    1.基础部分 在图中实现最基本的操作之一就是搜索从一个指定顶点可以到达哪些顶点,比如从武汉出发的高铁可以到达哪些城市,一些城市可以直达,一些城市不能直达.现在有一份全国高铁模拟图,要从某个城市(顶点) ...

  9. 深度优先搜索(DFS)和广度优先搜索(BFS)

    深度优先搜索(DFS) 广度优先搜索(BFS) 1.介绍 广度优先搜索(BFS)是图的另一种遍历方式,与DFS相对,是以广度优先进行搜索.简言之就是先访问图的顶点,然后广度优先访问其邻接点,然后再依次 ...

随机推荐

  1. 20155326《网络攻防》Exp4 恶意代码分析

    20155326<网络攻防>Exp4 恶意代码分析 基础问题回答: 1)如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操作有哪 ...

  2. rand_1tom 产生 rand_1ton

    给定一个等概率随机产生1~M的随机函数rand1ToM如下: public int rand1ToM(int m) { return (int) (Math.random() * m) + 1; } ...

  3. WebService接口定义及调用

    Web service是一个平台独立的,松耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML标准来描述.发布.发现.协调和配置这些应用程序,用于开发分布式的互操作的应用程序. WebS ...

  4. 2018CCPC-女生专场

    (咕咕咕,咕了快一年的bu题.. A.CCPC直播 传送:http://acm.hdu.edu.cn/showproblem.php?pid=6297 题意:rt. 分析:模拟. #include&l ...

  5. WannaCry勒索病毒全解读,权威修复指南大集合

    多地的出入境.派出所等公安网络疑似遭遇了勒索蠕虫病毒袭击,已暂时停办出入境业务:加油站突然断网,不能支持支付宝.微信.银联卡等联网支付:大批高校师生电脑中的文件被蠕虫病毒加密,需要支付相应的赎金方可解 ...

  6. MySQL:字符串字段加索引

    1. 使用方式 1.1 全字段加索引 给整个字段加索引,索引存储整个字段的值. 数据量较小时,查询成本高,准确度高: 数据量较大时,比较耗费空间: 1.2 前缀索引 MySQL支持前缀索引,可以定义字 ...

  7. MySQL 线程池&连接池&长连接&短连接

    线程池 简介 1.mysql每连接每线程,mysql都分配一个单独的线程,该线程处理客户端发来的所有命令 2.每个线程会占用一定的系统资源,线程数越多消耗的系统资源也越多 3.线程的创建和销毁有一定的 ...

  8. JS特效实现微博评论逻辑

    实现代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  9. scrapy 框架入门

    运行流程 官网:https://docs.scrapy.org/en/latest/intro/overview.html 流程图如下: 组件 1.引擎(EGINE):负责控制系统所有组件之间的数据流 ...

  10. 如何用java POI将word中的内容导入到mysql数据库中

    由于作业需要,要求我们将word文档中的数据直接导入到mysql中,在网上找了很常时间,终于将其解决. 由于比较初级,所以处理的word文档是那种比较规范的那种,条例比较清晰,设计的思路也比较简单,就 ...