HDU 2258 Continuous Same Game
HDU_2258
本来是Step里面遇到了HDU_2259的,结果发现要先做这个题……模拟题目中所说的规则就可以了。
#include<stdio.h> #include<string.h> #include<algorithm> #define MAXN 25 #define MAXD 410 int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1}, L; int N, M, a[MAXN][MAXN]; struct List {int x, y; }list[MAXD]; void init() {int i, j;char b[MAXN];for(i = N - 1; i >= 0; i --){scanf("%s", b);for(j = 0; j < M; j ++) a[i][j] = b[j] - '0';} } struct St {int N, M, g[MAXN][MAXN], cnt[MAXD], col[MAXN][MAXN];void init(int N, int M, int g[][MAXN]){this->N = N, this->M = M;memcpy(this->g, g, sizeof(this->g));}inline int inside(int x, int y){return x >= 0 && x < N && y >= 0 && y < M;}void color(int x, int y, int &cnt, int c){int i, nx, ny;col[x][y] = c, ++ cnt;for(i = 0; i < 4; i ++){nx = x + dx[i], ny = y + dy[i];if(inside(nx, ny) && g[nx][ny] == g[x][y] && !col[nx][ny])color(nx, ny, cnt, c);}}void erase(int x, int y){int i, nx, ny;g[x][y] = 0;for(i = 0; i < 4; i ++){nx = x + dx[i], ny = y + dy[i];if(inside(nx, ny) && col[x][y] == col[nx][ny] && g[nx][ny])erase(nx, ny);}}inline int find(int j){for(int i = 0; i < N; i ++) if(g[i][j]) return 0;return 1;}void arrange(){int i, j, k, kmax;kmax = 0;for(j = 0; j < M; j ++){k = 0;for(i = 0; i < N; i ++)if(g[i][j]){if(i != k)g[k][j] = g[i][j], g[i][j] = 0;++ k;}kmax = std::max(kmax, k);}N = kmax;k = 0;for(j = 0; j < M; j ++)if(!find(j)){if(j != k) for(i = 0; i < N; i ++) g[i][k] = g[i][j];++ k;}M = k;}int gogo(){int i, j, ans = 0, max, x, y, c;for(;;){max = c = 0;for(i = 0; i < N; i ++)for(j = 0; j < M; j ++) col[i][j] = 0;for(i = N - 1; i >= 0; i --)for(j = 0; j < M; j ++)if(g[i][j] && !col[i][j]){++ c, cnt[c] = 0;color(i, j, cnt[c], c);if(cnt[c] > max) max = cnt[c], x = i, y = j;}if(max <= 1) break;ans += (max - 1) * max;erase(x, y), arrange();}return ans;} }; void solve() {St st;st.init(N, M, a);printf("%d\n", st.gogo()); } int main() {while(scanf("%d%d", &N, &M) == 2){init();solve();}return 0; } /* Sample Input:5 5 32345 32345 32345 32345 121115 5 32223 32213 32223 32221 12111Sample Output:112 204*/
HDU 2258 Continuous Same Game相关推荐
- hdu 5079 Square
http://acm.hdu.edu.cn/showproblem.php?pid=5079 题意: n*n网格,每个格子可以涂黑色或白色,有的格子必须涂黑色 问最大白色正方形边长分别为0,1,2,- ...
- HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Sub ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDU 3132 Taunt Exposure Estimation(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3132 Problem Description The brave knights of Camelo ...
- HDU——1106排序(istringstream的使用、STLvector练习)
排序 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
- hdu 5438 Ponds 拓扑排序
Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...
- HDU 1248 寒冰王座(全然背包:入门题)
HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...
- hdu 1312 Red and Black 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 第二条深搜,题目并不难,但是做了我好久好久,由于一个细节,让我赌上了一个晚上的时间. 题目大意: ...
- HDU 1429 胜利大逃亡(续) (BFS+位压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 1272 小希的迷宫
Problem Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该 ...
最新文章
- MySQL—01—MySQL介绍和安装
- C语言、嵌入式位操作精华技巧大汇总
- 【SQL】服务器环境下的SQL
- Security+ 学习笔记52 风险管理
- Resteasy配置及其使用
- k8s kafka集群 连接不上_k8s利用statefulset部署kafka集群(依赖zookeeper)
- 关于RS485的使用
- 前端开发和后端开发究竟有什么区别?详细介绍
- Python的三元运算符
- linux基础-命令
- Count the Tetris
- 元阳科技签约欧洲细胞研究中心 获FRE独家运营权
- D2D第一个程序详解
- tornado web高级开发项目之抽屉官网的页面登陆验证、form验证、点赞、评论、文章分页处理、发送邮箱验证码、登陆验证码、注册、发布文章、上传图片...
- win10系统的计算机C盘在哪,win10系统只有一个C盘怎么解决
- 基于MATLAB的人脸识别 (1)
- uchar 和 uchar3的疑惑
- 华硕服务器主板z8na维修,华硕服务器主板Z8NA-D6提升企业绩效
- 这些黑客故事你尽管听,不奇葩算我输!
- 解决SpringBoot的yml配置文件报错: org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping