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

题干:

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

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440985.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

android 按钮按下缩放,android捏缩放

我TextView使用本教程为我实现了一个缩放缩放。结果代码是这样的&#xff1a;private GestureDetector gestureDetector;private View.OnTouchListener gestureListener;并在onCreate()中&#xff1a;// Zoom handlersgestureDetector new GestureDetector(new MyGestureDetec…

【CodeForces - 520B】Two Buttons (bfs或dp或时光倒流,trick)

题干&#xff1a; Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After click…

android代码旋转屏幕,Android Activity源码分析--windowmanager屏幕旋转研究

注意&#xff1a;鄙人看的是6.0的代码Activity里面还是调用了WindowManager来显示界面。在activity的738行&#xff0c;有这几行代码private Window mWindow;private WindowManager mWindowManager;/*package*/ View mDecor null; //这就是activity的主view&#xff0c;我也不…

android surfaceflinger 代码,android surfaceflinger测试程序

frameworks/base/libs/surfaceflinger/tests/resize/resize.cpp 是个好地方。 但是我的测试应用程序版本( 来自供应商的Eclair ) 过时了&#xff0c;有些 Surface API已经转移到 SurfaceControl&#xff0c;你必须&#xff1a;SurfaceComposerClient::createSurface() > Sur…

【牛客 - 315B】 勇气获得机(二叉树性质,思维,知识点,tricks)

题干&#xff1a; 妞妞听说Nowcoder Girl女生编程挑战赛要开始了, 但是她没有足够的勇气报名参加, 牛牛为了帮助妞妞,给她准备一台勇气获得机。初始的时候妞妞的勇气值是0, 勇气获得机有两个按钮: 1、N按钮: 如果当期拥有的勇气值为x, 按下之后勇气值将变为2*x1&#xff0c…

【CodeForces - 357C 】Knight Tournament(并查集 或 STLset)

题干&#xff1a; Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, youre just a simple peasant. …

qt android wifi,QtScrcpy: Android实时投屏软件,此应用程序提供USB(或通过TCP/IP)连接的Android设备的显示和控制。它不需要任何root访问权限...

QtScrcpyQtScrcpy可以通过USB(或通过TCP/IP)连接Android设备&#xff0c;并进行显示和控制。不需要root权限。单个应用程序最多支持16个安卓设备同时连接。同时支持GNU/Linux&#xff0c;Windows和MacOS三大主流桌面平台它专注于:精致 (仅显示设备屏幕)性能 (30~60fps)质量 (19…

android 添加so,Android studio 中添加 .so 文件

场景&#xff1a;Android studio 编译我的项目(项目中有运用的jni)&#xff0c;编译没有报错&#xff0c;正常的安装到我的机器上&#xff0c;可是运行的时候就报错&#xff0c;没有找到*.so文件...可是明明在libs&#xff0c;目录下有加相关的文件&#xff1f;参考网上大部分的…

【UVA - 10154 】Weights and Measures (贪心排序,dp,类似0-1背包,状态设定思维)

题干&#xff1a; The Problem Mack, in an effort to avoid being cracked, has enlisted your advice as to the order in which turtles should be dispatched to form Yertles throne. Each of the five thousand, six hundred and seven turtles ordered by Yertle has …

投票抵制华为鸿蒙系统,网友投票华为十大技术:鸿蒙OS仅排第二!

作为国内消费电子巨头&#xff0c;华为的技术实力是有目共睹的&#xff0c;在过去的一年发布的许多黑科技让人眼前一亮&#xff0c;那么今日(17日)消息&#xff0c;华为终端今天表示&#xff0c;此前向粉丝们征集票选过去这一年里大家最关注的十大功能技术。最终&#xff0c;收…

【牛客 - 318L】彪神666(水题,半高精度,递推,trick)

题干&#xff1a; 在国外&#xff0c;666代表魔鬼&#xff0c;777代表上帝。 所以牛逼的彪神就非常不喜欢6这个数字。 有一天彪神突发奇想&#xff0c;&#xff0c;他想求一些书与6无关的数。 如果一个数能被6整除&#xff0c;或者它的十进制表示法中某位上的数字为6&…

平板android怎么玩电脑游戏,Android平板模拟家用主机游戏教程_小米 平板_平板电脑新闻-中关村在线...

一、NESoid看完了上一页Windows系统模拟器介绍的网友应该能得出一个经验&#xff0c;一般模拟器的名称都和其模拟的游戏主机名称比较类似&#xff0c;所以很多模拟器都可以通过其名称判断出它到底是模拟谁的。比如这款NESoid&#xff0c;看名字就知道是模拟NES主机&#xff0c;…

【牛客 - 297B】little w and Sum(水题,前缀和)

题干&#xff1a; 小w与tokitsukaze一起玩3ds上的小游戏&#xff0c;现在他们遇到了难关。 他们得到了一个数列&#xff0c;通关要求为这个数列的和为0&#xff0c;并且只有一次改变一个数的符号的机会(正数变成负数&#xff0c;负数变成正数)。 请问小w与tokitsukaze能否…

华为nova 7 se鸿蒙,荣耀v40和华为Nova7Pro哪个好-参数对比-更值得入手

荣耀v40已经发布&#xff0c;今天小编给大家带来荣耀v40和华为Nova7Pro参数详细分析&#xff0c;这两款手机有什么区别&#xff0c;哪一个更加值得入手呢&#xff0c;一起来看看吧一、参数对比迷你手机网荣耀v40​华为Nova7Pro手机外形屏幕尺寸6.72英寸6.57屏幕材质OLEDOLED刷新…

【HDU - 1102】Constructing Roads (最小生成树裸题模板)

题干&#xff1a; There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if there is a road between A and B, or the…

【牛客 - 318M】被打脸的潇洒哥(几何问题,水题,结论,知识点)

题干&#xff1a; 平面上有n个圆&#xff0c;求使这n个圆两两相交&#xff08;即每两个圆之间恰好有两个交点&#xff09;后最多能把平面划分成多少个区域。 输入描述: 一个正整数t&#xff0c;表示有t(1≤t≤100)组数据。 接下来t行&#xff0c;每行一个整数n(0≤n≤…

html中列表前面的序号带圆圈,js动态添加带圆圈序号列表方法的精讲

免费学习推荐&#xff1a;js视频教程1、先在body里面添加ul标签2.通过js获取到id等于list的标签定义一个空字符串用来连接增加的标签&#xff0c;并展示出来如图的js代码展示的是前三个颜色不同&#xff0c;余下的颜色相同的圆圈序号function autoAddList(){var oUl document.…

【HDU - 1757】A Simple Math Problem (矩阵快速幂)

题干&#xff1a; Lele now is thinking about a simple function f(x). If x < 10 f(x) x. If x > 10 f(x) a0 * f(x-1) a1 * f(x-2) a2 * f(x-3) …… a9 * f(x-10); And ai(0<i<9) can only be 0 or 1 . Now, I will give a0 ~ a9 and two positive …

html边框自动变颜色,css怎么设置边框颜色?

元素外边距内就是元素的的边框 (border)。元素的边框就是围绕元素内容和内边据的一条或多条线。每个边框有 3 个方面&#xff1a;宽度、样式&#xff0c;以及颜色。下面我们就来看一下css设置边框颜色的方法。css可以使用border-color属性来设置边框颜色。border-color 属性是一…

【牛客 - 289 I】这是一个沙雕题I (字符串问题,水题)

题干&#xff1a; 因为毒瘤出题人出的题都太难了&#xff0c;于是gugugu打算出一个签到题&#xff0c;&#xff08;就是这题啦&#xff09;&#xff0c;这题很简单&#xff0c;给定一个字符串&#xff0c;请问你重新排序后能不能组成K个相同的字符串。 输入描述: 多组数据输…