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.

题解:想了好久,感觉要用到并查集,然后有点无从下手,然后参考了网上的博客,用暴力去给行涂色,再利用并查集的操作来维护列即可,但是G++通过不了

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std; const double pi=3.14; double eps=0.000001; int fa[100005];
int vis[100005];
int find(int x)
{
if (fa[x]==x)
return x;
else return fa[x]=find(fa[x]);
}
struct node
{
char op[12];
int x,y,z,d;
int e;
node() {}
}; node tm[100005];
int ans[10];
int main()
{
int n,m,k;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
memset(ans,0,sizeof ans);
for (int i=1; i<=k; i++)
{
scanf("%s%d%d%d%d",tm[i].op,&tm[i].x,&tm[i].y,&tm[i].z,&tm[i].d);
if (tm[i].op[0]=='R') scanf("%d",&tm[i].e);
} for (int j=0; j<n; j++)
{
for (int i=0; i<=m; i++) fa[i]=i,vis[i]=0;
for (int i=k; i>=1; i--)
{
int l,r,col=tm[i].d;
if (tm[i].op[0]=='C')
{
int up=tm[i].x+tm[i].z;
int down=tm[i].x-tm[i].z;
if (!(j>=down&&j<=up ))continue;
int tmp=tm[i].z*tm[i].z-(tm[i].x-j)*(tm[i].x-j);
tmp=sqrt(tmp);
l=tm[i].y-tmp;
r=tm[i].y+tmp;
}
if (tm[i].op[0]=='D')
{
int up=tm[i].x+tm[i].z;
int down=tm[i].x-tm[i].z;
if (!(j>=down&&j<=up ))continue;
l=tm[i].z-abs(j-tm[i].x);
r=tm[i].y+l;
l=tm[i].y-l;
}
if (tm[i].op[0]=='R')
{
col=tm[i].e;
int up=tm[i].x+tm[i].z-1;
int down=tm[i].x;
if (!(j>=down&&j<=up ))continue;
l=tm[i].y;
r=tm[i].y+tm[i].d-1;
}
if (tm[i].op[0]=='T')
{
int up=tm[i].x+(tm[i].z+1)/2-1;
int down=tm[i].x;
if (!(j>=down&&j<=up ))continue;
int tmp=(tm[i].z-1)/2+(tm[i].x-j);
l=tm[i].y-tmp;
r=tm[i].y+tmp;
}
l=max (l,0);
r=min(r,m-1);
int fx=find(l);
for (int i=r; i>=l;)
{
int fy=find(i);
if (!vis[fy]) ans[col]++;
vis[fy]=1;
if (fx!=fy) fa[fy]=fx;
i=fy-1;
}
}
}
for (int i=1; i<=9; i++)
{
if (i>1) printf(" ");
printf("%d",ans[i]);
}
printf("\n");
}
return 0;
}

Draw a Mess (并查集)的更多相关文章

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

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

  2. uva 1493 - Draw a Mess(并查集)

    题目链接:uva 1493 - Draw a Mess 题目大意:给定一个矩形范围,有四种上色方式,后面上色回将前面的颜色覆盖,最后问9种颜色各占多少的区域. 解题思路:用并查集维护每一个位置相应下一 ...

  3. UVA 1493 Draw a Mess(并查集+set)

    这题我一直觉得使用了set这个大杀器就可以很快的过了,但是网上居然有更好的解法,orz... 题意:给你一个最大200行50000列的墙,初始化上面没有颜色,接着在上面可能涂四种类型的形状(填充):  ...

  4. 并查集(涂色问题) HDOJ 4056 Draw a Mess

    题目传送门 题意:给出一个200 * 50000的像素点矩阵,执行50000次操作,每次把一个矩形/圆形/菱形/三角形内的像素点涂成指定颜色,问最后每种颜色的数量. 分析:乍一看,很像用线段树成段更新 ...

  5. 【HDOJ】4056 Draw a Mess

    这题用线段树就MLE.思路是逆向思维,然后每染色一段就利用并查集将该段移除,均摊复杂度为O(n*m). /* 4056 */ #include <iostream> #include &l ...

  6. POJ 2912 - Rochambeau - [暴力枚举+带权并查集]

    题目链接:http://poj.org/problem?id=2912 Time Limit: 5000MS Memory Limit: 65536K Description N children a ...

  7. CodeForces Roads not only in Berland(并查集)

    H - Roads not only in Berland Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

  8. POJ2912 Rochambeau [扩展域并查集]

    题目传送门 Rochambeau Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4463   Accepted: 1545 ...

  9. POJ2912:Rochambeau(带权并查集)

    Rochambeau Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5208   Accepted: 1778 题目链接:h ...

随机推荐

  1. oddjob之smooth关闭程序

    java程序的smooth关闭策略可以采用hook跟观察者的模式实现 无限等状态,如果状态出现可以关闭的事件则进行关闭 虚拟机的关闭通过钩子调用关闭,如果关闭失败,在超时时间内强制杀掉jvm 状态类 ...

  2. poj 2388 Who's in the Middle(快速排序求中位数)

    一.Description FJ is surveying his herd to find the most average cow. He wants to know how much milk ...

  3. Python:.join()函数

    转于:https://blog.csdn.net/chixujohnny/article/details/53301995 博主:chixujohnny 介绍:.join是一个字符串操作函数,将元素相 ...

  4. JVM体系结构之六:堆Heap之2:新生代及新生代里的两个Survivor区(下一轮S0与S1交换角色,如此循环往复)、常见调优参数

    一.为什么会有年轻代 我们先来屡屡,为什么需要把堆分代?不分代不能完成他所做的事情么?其实不分代完全可以,分代的唯一理由就是优化GC性能.你先想想,如果没有分代,那我们所有的对象都在一块,GC的时候我 ...

  5. Linux 文件名颜色

    在Linux中,文件的颜色都是有含义的.其中, 蓝色表示目录 绿色表示可执行文件 红色表示压缩文件 浅蓝色表示链接文件 灰色表示其它文件 红色闪烁表示链接的文件有问题了 黄色是设备文件,包括block ...

  6. Bluetooth Functions

    The functions in this section are used for managing Bluetooth devices and services. Bluetooth is als ...

  7. Matlab数据类型的转换

    Matlab中有15种基本数据类型,主要是整型.浮点.逻辑.字符.日期和时间.结构数组.单元格数组以及函数句柄等. 1.整型:(int8:uint8:int16:uint16:int32:uint32 ...

  8. 【spring boot logback】日志颜色渲染,使用logback-spring.xml自定义的配置文件后,日志没有颜色了

    接着spring boot日志logback解析之后,发现使用logback-spring.xml自定义的配置文件后,日志没有颜色了 怎么办? 官网处理日志链接:https://logback.qos ...

  9. 8、scala面向对象编程之Trait

    一.Trait基础 1.将trait作为接口使用 // Scala中的Triat是一种特殊的概念 // 首先我们可以将Trait作为接口来使用,此时的Triat就与Java中的接口非常类似 // 在t ...

  10. Git删除master branch中最近一次的提交

    在做一个项目的过程中,需要删除master brach中最近一次的提交,需要在Git repository中删除 采用步骤如下: 1. 在Visual Studio中打开项目,进入到master br ...