UVa 10946 - You want what filled?
来源:互联网 发布:淘宝宝贝主图大小 编辑:程序博客网 时间:2024/05/22 07:59
题目:统计一个矩阵中所有的连通块的个数,按递减输出。
分析:搜索,floodfill。直接利用dfs求解即可。
说明:数组开小了╮(╯▽╰)╭。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;char maps[55][55];typedef struct tnode{char ch;int count;}type;type data[2000];int dfs(int x, int y, int n, int m, char c){if (x < 0 || x >= n || y < 0 || y >= m) return 0;if (maps[x][y] != c) return 0;maps[x][y] = '.';int sum = 1;sum += dfs(x+1, y, n, m, c);sum += dfs(x-1, y, n, m, c);sum += dfs(x, y+1, n, m, c);sum += dfs(x, y-1, n, m, c);return sum;}int cmp(type a, type b){if (a.count != b.count)return a.count > b.count;return a.ch < b.ch;}int main(){int n,m,temp,cas = 1;while (~scanf("%d%d",&n,&m) && m) {for (int i = 0 ; i < n ; ++ i)scanf("%s",maps[i]);int count = 0;for (int i = 0 ; i < n ; ++ i)for (int j = 0 ; j < m ; ++ j) if (maps[i][j] != '.') {data[count].ch = maps[i][j];data[count].count = dfs(i, j, n, m, maps[i][j]);count ++;}sort(data, data+count, cmp);printf("Problem %d:\n",cas ++);for (int i = 0 ; i < count ; ++ i)printf("%c %d\n",data[i].ch,data[i].count);}return 0;}
0 0
- UVa 10946 - You want what filled?
- UVa 10946 Do You What Filled? (DFS)
- Focus on what you want
- You can't get what you want,till you know what you want!
- Is this really what you want?
- do what you want to do and be youself
- 自己想要的到底是什么?what do you want?
- 【HDU】5736 Call It What You Want【暴力+dp】
- Hello Mr.J——What do you want?Mycat~
- So you want to be a 2n-aire? UVA
- Follow your heart, always remember who you are, what you want to be.
- Top 10 Things Customers Don't Want to Hear And What You Should Say Instead
- Inside Internet Security:What Hackers Don't Want You To Know
- What .h file should be include if you want to use colorref
- What I want for you 奥巴马给女儿的信
- [Cocoa]_[初级]_[Removing All Custom Views or what you want to removed]
- warning: its scope is only this definition or declaration, which is not what you want
- Search what you want by english instand of chinese from now on
- jdk环境设置
- 理解OAuth 2.0
- Android 多屏适配解决方案
- handler
- LeetCode-Evaluate Reverse Polish Notation
- UVa 10946 - You want what filled?
- git新建一个分支--set-upstream
- C++中的virtual
- 二叉树的深度优先遍历和广度优先遍历
- 【无限互联】学员作品:糗事百科
- 【书摘】《代码大全》- “良好的封装”
- HDU 3018 Ant Trip
- Python time datetime 模块梳理
- 45个实用的JavaScript技巧、窍门和最佳实践