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. ACM学习历程—Hihocoder [Offer收割]编程练习赛1

    比赛链接:http://hihocoder.com/contest/hihointerview3/problem/1 大概有一个月没怎么打算法了.这一场的前一场BC,也打的不是很好.本来Div1的A和 ...

  2. 【Tensorflow】Ubuntu 安装 Tensorflow gpu

    安装环境:Ubuntu 16.04lts 64位,gcc5.4 1.安装Cuda 1. 下载cuda toolkit. 下载cuda8.0 地址:https://developer.nvidia.co ...

  3. Linux IO实时监控iostat命令详解(转)

    简介 iostat主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之后运行iostat将显示自上次运行该命令以后的统计信息.用户可以通过指定统计的次数和时间 ...

  4. B+树索引和哈希索引的明显区别是:

    如果是等值查询,那么哈希索引明显有绝对优势,因为只需要经过一次算法即可找到相应的键值:当然了,这个前提是,键值都是唯一的.如果键值不是唯一的,就需要先找到该键所在位置,然后再根据链表往后扫描,直到找到 ...

  5. 【转】 Pro Android学习笔记(七一):HTTP服务(5):多线程调用HttpClient

    目录(?)[-] 应用共享HttpClient对象的同步问题 创建共享HttpClient代码 创建共享对象 创建可共享的HttpClient对象 使用共享HttpClient对象的代码 基础代码 修 ...

  6. js---倒计时的自动跳转.html

    ============================================================================== 倒计时的自动跳转.html <!DO ...

  7. Python函数(十二)-迭代器

    字符串,列表,元组,字典,集合,生成器这些能通过for循环来遍历的数据类型都是可迭代对象 可通过isinstance判断是不是可迭代对象 >>> from collections i ...

  8. hbase java API跟新数据,创建表

    package hbaseCURD; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import o ...

  9. redis 有用 Sorted-Set 应用场景

    1.1.1Set数据类型的 使用场景 1.可以使用Redis的Set数据类型跟踪一些唯一性数据,比如访问某一博客的唯一IP地址信息.对于此场景,我们仅需在每次访问该博客时将访问者的IP存入Redis中 ...

  10. Learning Python 012 函数式编程 1 高阶函数

    Python 函数式编程 1 高阶函数 高阶函数 Q:什么是高阶函数? A:一个函数接收另一个函数作为参数,这种函数就称之为高阶函数. 简单举个例子: def add(x, y, f): return ...