2019 GDUT Rating Contest I : Problem C. Mooyo Mooyo
题面:
C. Mooyo Mooyo
0000000000
0000000300
0054000300
1054502230
2211122220
1111111223
0000000000
0000000300
0054000300
1054502230
2211122220
1111111223
0000000000
0000000300
0054000300
1054500030
2200000000
0000000003
0000000000
0000000000
0000000000
0000000000
1054000300
2254500333
0000000000
0000000000
0000000000
0000000000
1054000000
2254500000
题目描述:
题目分析:
1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <cmath>
5 #include <algorithm>
6 using namespace std;
7 int n, k;
8 char s[105][15];
9 int vis[105][15]; //记录点是否被访问过
10 int dr[4] = {-1, 1, 0, 0}, dc[4] = {0, 0, -1, 1}; //方向:上下左右
11 int cnt; //记录连通的数字
12
13 void down(){ //重力下落
14 for(int i = n-1; i >= 1; i--){
15 for(int j = 0; j < 10; j++){
16 for(int k = i; k < n && s[k][j] == '0'; k++){
17 s[k][j] = s[k-1][j];
18 s[k-1][j] = '0';
19 }
20 }
21 }
22 }
23
24 int check(int r, int c){ //检查函数
25 if(r < 0 || r >= n || c < 0 || c >= 10) return 0;
26 if(vis[r][c]) return 0;
27 return 1;
28 }
29
30 void dfs(int r, int c){
31
32 vis[r][c] = 1; //每到一个点就标记一下
33 cnt++;
34 for(int i = 0; i < 4; i++){
35 int R = r+dr[i], C = c+dc[i];
36 if(check(R, C) && s[R][C] == s[r][c]){
37 dfs(R, C);
38 }
39 }
40 }
41
42 void clear_num(int r, int c, int ch){ //清空操作
43 s[r][c] = '0';
44 for(int i = 0; i < 4; i++){
45 int R = r+dr[i], C = c+dc[i];
46 if( (r >= 0 && r < n && c >= 0 && c < 10) && s[R][C] == ch){
47 clear_num(R, C, ch);
48 }
49 }
50
51 }
52
53
54 int main(){
55 cin >> n >> k;
56 for(int i = 0; i < n; i++) cin >> s[i];
57
58 while(1){
59
60 memset(vis, 0, sizeof(vis)); //清空vis数组
61
62 int flag = 1; //是否有大于等于K的连通数字的标志
63 for(int i = 0; i < n; i++){
64 for(int j = 0; j < 10; j++){
65 if(s[i][j] != '0') {
66 cnt = 0;
67 dfs(i, j);
68 if(cnt >= k) {
69 flag = 0;
70 clear_num(i, j, s[i][j]);
71 }
72 }
73 }
74 }
75
76 down();
77
78 if(flag) break; //没有大于等于K的连通块,结束
79
80
81 }
82
83 for(int i = 0; i < n; i++){
84 for(int j = 0; j < 10; j++){
85 cout << s[i][j];
86 }
87 cout << endl;
88 }
89
90 return 0;
91 }
2019 GDUT Rating Contest I : Problem C. Mooyo Mooyo的更多相关文章
- 2019 GDUT Rating Contest II : Problem F. Teleportation
题面: Problem F. Teleportation Input file: standard input Output file: standard output Time limit: 15 se ...
- 2019 GDUT Rating Contest III : Problem D. Lemonade Line
题面: D. Lemonade Line Input file: standard input Output file: standard output Time limit: 1 second Memo ...
- 2019 GDUT Rating Contest I : Problem H. Mixing Milk
题面: H. Mixing Milk Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest I : Problem A. The Bucket List
题面: A. The Bucket List Input file: standard input Output file: standard output Time limit: 1 second Me ...
- 2019 GDUT Rating Contest I : Problem G. Back and Forth
题面: G. Back and Forth Input file: standard input Output file: standard output Time limit: 1 second Mem ...
- 2019 GDUT Rating Contest III : Problem E. Family Tree
题面: E. Family Tree Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe
题面: C. Team Tic Tac Toe Input file: standard input Output file: standard output Time limit: 1 second M ...
- 2019 GDUT Rating Contest III : Problem A. Out of Sorts
题面: 传送门 A. Out of Sorts Input file: standard input Output file: standard output Time limit: 1 second M ...
- 2019 GDUT Rating Contest II : Problem G. Snow Boots
题面: G. Snow Boots Input file: standard input Output file: standard output Time limit: 1 second Memory ...
随机推荐
- anaconda + pyqt5 + pycharm 安装,测试
1. 安装sip pip install sip 2.安装pyqt5 pip install PyQt5 pip install PyQt5-tools -i http://pypi.douban.c ...
- vagrant + virtualbox安装centos环境+docker安装
1. 下载vagrant 并安装,安装完成后,输入vagrant回车查看是否安装成功 2. 下载virtualbox.box并安装,安装完成后. 3. 创建虚拟机文件夹,例如.F:/vmimg/fir ...
- JVM 报 GC Overhead limit exceeded 是什么意思?
默认情况下,并不是等堆内存耗尽,才会报 OutOfMemoryError,而是如果 JVM 觉得 GC 效率不高,也会报这个错误. 那么怎么评价 GC 效率不高呢?来看下源码: 呢?来看下源码gcOv ...
- JVM系列之一 JVM的基础概念与内存区域
前言 作为一名 Java 语言的使用者,学习 JVM 有助于解决程序运行过程中出现的问题.写出性能更高的代码. 可以说:学好 JVM 是成为中高级 Java 工程师的必经之路. 有感于从未整理归纳 J ...
- 系统扩展与 macOS 不兼容
系统扩展与 macOS 不兼容 某些系统扩展与当前版本的 macOS 不兼容或将与后续 macOS 版本不兼容 https://support.apple.com/zh-cn/HT210999 ref ...
- base 64 & blob & image url
base 64 & blob & image url base 64 image & e.clipboardData.items[1] https://codepen.io/x ...
- ORM & sequelize
ORM Object Relational Mapping 对象关系映射 Table => Object, 简化 SQL 查询命令的编写 https://en.wikipedia.org/wik ...
- Github 获取仓库的releases API
API 文档 example: 这将获取所有的版本 https://api.github.com/repos/januwA/flutter_anime_app/releases 最新版本: https ...
- 使用hive增量更新
目录 1.增量更新 2.对第一种情况 2.1.准备工作 2.2.更新数据 3.对第二种情况 3.1.准备工作 3.2.方法1 3.3.方法2 参考文末文章,加上自己的理解. 1.增量更新 有一个 ba ...
- 手把手教你Centos7 部署 gitlab社区版
一.前置说明: 操作系统:Centos 7 物理内存:>=2G 本人亲测,如果安装低版本的gitlab,比如我这里所使用的v8.17.0,物理内存1G,swap 2G虚拟内存即可部署.高版本的所 ...