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;
}

最新文章

  1. 关于ajax的同步和异步
  2. Book LIst
  3. Maven报错: Missing artifact jdk.tools:jdk.tools:jar:1.7
  4. php二维数组的取值与转换
  5. IM架构(一)JSQMessagesViewController
  6. Learn sed using these command on Linux(流线式编辑器——sed)
  7. C++盲点
  8. LINE最新版6.5.0在iOS上的删除信息取证
  9. Socket基础编程
  10. MLlib 卡方检验
  11. 解析:用 CSS3 和 JavaScript 制作径向动画菜单
  12. js 计算过去和未来的时间距离现在多少天?
  13. Linux学习之sudo命令
  14. 开源API测试工具 Hitchhiker v0.4更新 - 没有做不到,只有想不到
  15. KnockoutJS-快速入门
  16. tp5 自定义排序
  17. 简单几步,教你学会PHP,新手必看!
  18. 用HTML+CSS实现一个计科院网站首页静态页面
  19. SpringMVC学习二
  20. Tomcat 之session 持久化2

热门文章

  1. bzoj 2594: 水管局长数据加强版 Link-Cut-Tree
  2. bzoj 2395 Timeismoney —— 最小乘积生成树
  3. java中的设计模式及其六大原则
  4. Azure blob Storage Snapshot
  5. Erlang pool management -- Emysql pool
  6. dubbo、dubbox、motan、thrift、grpc等RPC框架比较及选型
  7. web攻击之二:CSRF跨站域请求伪造
  8. 二 kafka设计原理
  9. Python模块-requests(一)
  10. 共有11款Python 中文分词库开源软件