题干:

It's graduated season, every students should leave something on the wall, so....they draw a lot of geometry shape with different color.

When teacher come to see what happened, without getting angry, he was surprised by the talented achievement made by students. He found the wall full of color have a post-modern style so he want to have an in-depth research on it.

To simplify the problem, we divide the wall into n*m (1 ≤ n ≤ 200, 1 ≤ m ≤ 50000) pixels, and we have got the order of coming students who drawing on the wall. We found that all students draw four kinds of geometry shapes in total that is Diamond, Circle, Rectangle and Triangle. When a student draw a shape in pixel (i, j) with color c (1 ≤ c ≤ 9), no matter it is covered before, it will be covered by color c.

There are q (1 ≤ q ≤ 50000) students who have make a drawing one by one. And after q operation we want to know the amount of pixels covered by each color.

Input

There are multiple test cases.

In the first line of each test case contains three integers n, m, q. The next q lines each line contains a string at first indicating the geometry shape:

* Circle: given xc, yc, r, c, and you should cover the pixels(x, y) which satisfied inequality (x - xc) 2 + (y - yc) 2 ≤ r 2 with color c; 
* Diamond: given xc, yc, r, c, and you should cover the pixels(x, y) which satisfied inequality abs(x - xc) + abs(y - yc) ≤ r with color c; 
* Rectangle: given xc, yc, l, w, c, and you should cover the pixels(x, y) which satisfied xc ≤ x ≤ xc+l-1, yc ≤ y ≤ yc+w-1 with color c; 
* Triangle: given xc, yc, w, c, W is the bottom length and is odd, the pixel(xc, yc) is the middle of the bottom. We define this triangle is isosceles and the height of this triangle is (w+1)/2, you should cover the correspond pixels with color c;

Note: all shape should not draw out of the n*m wall! You can get more details from the sample and hint. (0 ≤ xc, x ≤ n-1, 0 ≤ yc, y ≤ m-1)

Output

For each test case you should output nine integers indicating the amount of pixels covered by each color.

Sample Input

8 8 4
Diamond 3 3 1 1
Triangle 4 4 3 2
Rectangle 1 1 2 2 3
Circle 6 6 2 4

Sample Output

4 4 4 11 0 0 0 0 0

Hint

The final distribution of different colors:
00000000
03300000
03310000
00111000
00022240
00002444
00004444
00000444

解题报告:

其实这题建20棵线段树也可以轻松解决,,不过因为数据加强了好像zoj上会被T(因为内存给的很宽松)hdu上会MLE

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
struct Node {char op[15];int x,y,l,w,c;
} node[MAX];
int f[MAX],ans[MAX];
int n,m,q;
bool vis[MAX];
int getf(int v) {return v == f[v] ? v : f[v] = getf(f[v]);
}
void merge(int u,int v) {int t1 = getf(u);int t2 = getf(v);if(t1!=t2) f[t2]=t1;//都归到左侧的t1上。。
}
int main()
{   while(~scanf("%d%d%d",&n,&m,&q)) {for(int i = 1; i<=q; i++) {scanf("%s",node[i].op);if(node[i].op[0] == 'R') scanf("%d%d%d%d%d",&node[i].x,&node[i].y,&node[i].l,&node[i].w,&node[i].c);else scanf("%d%d%d%d",&node[i].x,&node[i].y,&node[i].l,&node[i].c);}memset(ans,0,sizeof ans);for(int r = 0; r<n; r++) {for(int c=0; c<m; c++) vis[c]=0,f[c]=c;for(int i = q; i>=1; i--) {int L,R,col = node[i].c;if(node[i].op[0] == 'C') {if(node[i].l < abs(r-node[i].x)) continue;int tmp = (int)sqrt(node[i].l*node[i].l - (r-node[i].x) * (r-node[i].x));//半径^2 - 竖直长度= 投影长度 L=node[i].y-tmp;R=node[i].y+tmp; }if(node[i].op[0] == 'D') {if(node[i].l < abs(r-node[i].x)) continue;int tmp = node[i].l - abs(r-node[i].x);L=node[i].y-tmp;R=node[i].y+tmp;}if(node[i].op[0] == 'R') {if(r > node[i].x+node[i].l-1 || r < node[i].x) continue;L=node[i].y;R=node[i].y+node[i].w-1;}if(node[i].op[0] == 'T'){if(r-node[i].x >= (node[i].l+1)/2 || r<node[i].x) continue;int tmp = (node[i].l-1)/2 - (r-node[i].x);L=node[i].y-tmp;R=node[i].y+tmp;}L=max(0,L);R=min(R,m-1);int t1 = getf(L),t2;for(int c = R; c>=L; c=t2-1) {t2=getf(c);if(vis[t2]==0) ans[col]++,vis[t2]=1;//这里必须是标记t2,不能直接标记c。。因为你就不好查询是否被标记过了,,总之这里并查集都是用根节点进行操作,所以都转化成根节点就行了。 merge(t1,t2);}}}for(int i = 1; i<=9; i++) {printf("%d%c",ans[i],i==9?'\n':' ');}}return 0 ;}

【HDU - 4056】Draw a Mess (并查集 or 线段树)相关推荐

  1. UVA1493 - Draw a Mess(并查集)

    UVA1493 - Draw a Mess(并查集) 题目链接 题目大意:一个N * M 的矩阵,每次你在上面将某个范围上色,不论上面有什么颜色都会被最新的颜色覆盖,颜色是1-9,初始的颜色是0.最后 ...

  2. HDU 5575 Discover Water Tank 并查集+左偏树

    不妨假定初始答案为所有的无水询问,因为这样一定没有冲突. 然后枚举有水询问.水位线到这里时,答案能否更优. 若水位线达到某一高度,则可能淹没旁边的水箱,那么实际就变成了一个大水箱,所以考虑用并查集来优 ...

  3. POJ 1944 Fiber Communications (枚举 + 并查集 OR 线段树)

    题意 在一个有N(1 ≤ N ≤ 1,000)个点环形图上有P(1 ≤ P ≤ 10,000)对点需要连接.连接只能连接环上相邻的点.问至少需要连接几条边. 思路 突破点在于最后的结果一定不是一个环! ...

  4. 分门别类刷leetcode——高级数据结构(字典树,前缀树,trie树,并查集,线段树)

    目录 Trie树(字典树.前缀树)的基础知识 字典树的节点表示 字典树构造的例子 字典树的前序遍历 获取字典树中全部单词 字典树的整体功能 字典树的插入操作 字典树的搜索操作 字典树的前缀查询 字典树 ...

  5. Gym - 101194G Pandaria (并查集+倍增+线段树合并)

    题意: 给定一个无向图.每个点有一种颜色.现在给定q个询问,每次询问x和w,求所有能通过边权值不超过w的边走到x的点的集合中,哪一种颜色的点出现的次数最多.次数相同时输出编号最小的那个颜色.强制在线. ...

  6. How Many Answers Are Wrong HDU - 3038(带权并查集经典题,满满的都是注释)

    How Many Answers Are Wrong HDU - 3038  点击打开链接 题意:现在有n个数(你并不知道这n个数是什么),m次查询,每次查询给出u,v,w.表示从第u个数到第v个数的 ...

  7. hdu 1232 畅通工程 最小生成树 并查集

    1232的连接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 #include <iostream>#include <cstdio& ...

  8. HDU 1213 How Many Tables 并查集 水~

    http://acm.hdu.edu.cn/showproblem.php?pid=1213 果然是需要我陪跑T T,禽兽工作人员还不让,哼,但还是陪跑了~ 啊,还有呀,明天校运会终于不用去了~耶耶耶 ...

  9. hdu 3234 Exclusive-OR 题解(并查集,思维)

    该死的期末复习终于结束了... 暑假来了\color{#ff0000}{暑假来了}暑假来了!!! 所以我就珂以非常开心的写博客了. 原题链接: hdu 题意简述 多组数据.你有一个没有确定的数列.有一 ...

最新文章

  1. 阅读《Android 从入门到精通》(29)——四大布局
  2. i.MX 系列CPU HAB漏洞SecureBoot漏洞
  3. Qt网络编程之UDP编程练习(20200219)
  4. VS2013建立C++ dll库文件
  5. snmp v3 参数_snmp v3 配置
  6. Java行为参数化(一)
  7. 玩Docker只要浏览器就够了,PWD是个神奇的网站
  8. python scipy库函数solve用法_如何在中使用事件scipy.integrate.solve_ivp
  9. 【小白集合】详解服务器内存和显存基础知识
  10. 远程办公(2)-重新定义“雇佣关系”:交易成果,而不是时间
  11. 计算机网络学习(九)—应用层的概述
  12. 超简单的html登录界面
  13. 浅聊||高速PCB过孔设计需要注意这些问题
  14. py的征途2之简例分享
  15. java mac算法_银行业加密算法,MAC算法算法(java-国密)
  16. 三极管死区电压和导通电压的区别
  17. 汽车零部件行业需求分析及解决方案
  18. docker应用篇(6):安装Uptime Kuma监控
  19. java实现区块链_用Java实现一个简单的区块链
  20. 串口接收完整一帧数据包的3种方法

热门文章

  1. 140. Word Break II
  2. [密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第31篇]Game Hopping证明
  3. python的concat用法_python的concat等多种用法详解
  4. python 字符串截取_Python 字符串操作实现代码(截取/替换/查找/分割)
  5. 计算机用户名登陆管理员权限,关于win10勿删用户账号下管理员身份导致无法登录系统的问题...
  6. java 强制向上转型,Java 转型(向上或向下转型)详解及简单实例
  7. 1245C. Constanze‘s Machine
  8. java实现gdal栅格矢量化,《GDAL源码剖析与开发指南》一一1.5 GDAL源码目录
  9. springboot整合elasticsearch_Spring Boot学习10_整合Elasticsearch
  10. java中软填空面试题,通过这9个Java面试题,就可以入职华为啦