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

UVA1493 - Draw a Mess(并查集) 题目链接 题目大意:一个N * M 的矩阵,每次你在上面将某个范围上色,不论上面有什么颜色都会被最新的颜色覆盖,颜色是1-9,初始的颜色是0.最后输出这个矩形中.每一个颜色有多少个.某个范围这个分为了四种,圆,矩形,菱形,还有正三角形(倒着的).注意这题的边界,不能超出这个矩形,非常easy越界. 解题思路:由于题的矩阵范围是200 * 50000,然后操作又是50000,这样三个相乘,即使给60s也是不够的.由于行的数目比較少.假设每次都能…
题目链接:uva 1493 - Draw a Mess 题目大意:给定一个矩形范围,有四种上色方式,后面上色回将前面的颜色覆盖,最后问9种颜色各占多少的区域. 解题思路:用并查集维护每一个位置相应下一个能够上色的位置.然后将上色倒转过来处理,就攻克了颜色覆盖的问题. #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm&g…
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…
这题我一直觉得使用了set这个大杀器就可以很快的过了,但是网上居然有更好的解法,orz... 题意:给你一个最大200行50000列的墙,初始化上面没有颜色,接着在上面可能涂四种类型的形状(填充): 圆 :给你圆心坐标,半径,颜色 (1->9) 菱形 :中心坐标,中心向四方的最大值,颜色(1->9) 矩形 :左上角坐标,长和宽,颜色(1->9) 等腰三角形:底边中心坐标,底边长(+1再/2 就是高),颜色(1->9) 其中输入的坐标一定在墙上,但是其他地方可能越界,所以要处理好. …
题目传送门 题意:给出一个200 * 50000的像素点矩阵,执行50000次操作,每次把一个矩形/圆形/菱形/三角形内的像素点涂成指定颜色,问最后每种颜色的数量. 分析:乍一看,很像用线段树成段更新写,虽然复杂度有点大,但是也想不到其他的方法.这题可以巧妙地运用并查集来涂色.离线,从最后一个倒过来涂色,保证能涂上去的一定不会被覆盖,每次扫描一行,将一条线上的点都合并到右端点. #include <bits/stdc++.h> using namespace std; #define lson…
这题用线段树就MLE.思路是逆向思维,然后每染色一段就利用并查集将该段移除,均摊复杂度为O(n*m). /* 4056 */ #include <iostream> #include <sstream> #include <string> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #incl…
题目链接:http://poj.org/problem?id=2912 Time Limit: 5000MS Memory Limit: 65536K Description N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest children are divided into three groups (it is possible t…
H - Roads not only in Berland Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 25D Description Berland Government decided to improve relations with neighboring countries. First of all, it…
题目传送门 Rochambeau Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4463   Accepted: 1545 Description N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest children are divided into three…
Rochambeau Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5208   Accepted: 1778 题目链接:http://poj.org/problem?id=2912 Description: N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest c…