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 ...
随机推荐
- 【非原创】ZOJ - 4062 Plants vs. Zombies【二分】
题目:戳这里 题意:机器人走过一个花,可以给那个花浇水,给定步数下,问花的最小的最大能量值. 学习博客:戳这里 本人代码: 1 #include <bits/stdc++.h> 2 typ ...
- C++ part2
为什么析构函数必须是虚函数?为什么C++默认的析构函数不是虚函数? references: nowcoder 将可能会被继承的父类的析构函数设置为虚函数,可以保证当我们new一个子类,然后使用基类指针 ...
- bzoj4695 最假女选手(势能线段树/吉司机线段树)题解
题意: 已知\(n\)个数字,进行以下操作: \(1.\)给一个区间\([L,R]\) 加上一个数\(x\) \(2.\)把一个区间\([L,R]\) 里小于\(x\) 的数变成\(x\) \(3.\ ...
- Web 前端如何优雅的处理海量数据
Web 前端如何优雅的处理海量数据 Q: 如何在 Web 页面上处理上亿条后端返回的数据,并且保证 UI 展示的流畅性 A: 思路: 时间分片, 批处理,Buffer 缓存,虚拟滚动,Web Work ...
- OTA development
OTA development OTA update OTA Over the Air / 无线下载 https://en.wikipedia.org/wiki/Over-the-air_progra ...
- JUC并发集合类CopyOnWriteList
CopyOnWriteList简介 ArrayList是线程不安全的,于是JDK新增加了一个线程并发安全的List--CopyOnWriteList,中心思想就是copy-on-write,简单来说是 ...
- django学习-17.如何提供一个规范的接口返回值
目录结构 1.前言 2.进行实际的一个完整流程操作 2.1.第一步:编写一个用于查询用户数据的视图函数 2.2.第二步:编写对应的一个url匹配规则 2.3.第三步:启动django项目[hellow ...
- 【转】奇异值分解(SVD)原理详解及推导
原文地址:https://blog.csdn.net/zhongkejingwang/article/details/43053513,转载主要方便随时查阅,如有版权要求,请及时联系. 在网上看到有很 ...
- Linux下安装mysql-5.7.28详细步骤
一.下载Mysql 下载地址:https://downloads.mysql.com/archives/community/ 二.环境配置 检测系统是否自带Mysql # rmp -qa|grep m ...
- Django简单的使用及一些基础方法
目录 一.静态文件配置 1. 什么是静态文件 2. 静态文件的用法 3. 静态文件的动态绑定 二.请求方式与相应 1. get请求 2. post请求 3. Django后端视图函数处理请求 三.re ...