UVA - 657 The die is cast
2016-08-10 21:50
357 查看
题目大意:求骰子上的点数并按升序输出。. 为背景,* 为骰子, X 为点数,有公共边相邻点数为 1,即上下左右才算相邻。
解题思路:类似上一题油田的,多了一层遍历。查找骰子即 *,然后在骰子上查找点数即 X,双重 dfs。
没想到这题能过,觉得写的时候挺乱的- -
debug 里面的样例输入和搜到的几个 AC 输出不太一样……迷
解题思路:类似上一题油田的,多了一层遍历。查找骰子即 *,然后在骰子上查找点数即 X,双重 dfs。
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> using namespace std; char map[100][100]; int cn, cnt, tot, w, h; int num[1000]; void dfs2(int r, int c, int cn) { if (r < 0 || r >= h || c < 0 || c >= w) return; if (map[r][c] != 'X') return; map[r][c] = '*'; dfs2(r-1, c, cn); dfs2(r, c-1, cn); dfs2(r, c+1, cn); dfs2(r+1, c, cn); } void dfs1(int r, int c) { if (r < 0 || r >= h || c < 0 || c >= w || map[r][c] == '.') return; if (map[r][c] == 'X') dfs2(r, c, ++num[tot]); map[r][c] = '.'; dfs1(r-1, c); dfs1(r, c-1); dfs1(r, c+1); dfs1(r+1, c); } int main() { while (scanf("%d%d", &w, &h) != EOF && w && h) { printf("Throw %d\n", ++cnt); memset(num, 0, sizeof(num)); tot = 0; for (int i = 0; i < h; i++) scanf("%s", map[i]); for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) if (map[i][j] == '*') { dfs1(i, j); tot++; } sort(num, num+tot); for (int i = 0; i < tot-1; i++) printf("%d ", num[i]); printf("%d\n\n",num[tot-1]); } }
没想到这题能过,觉得写的时候挺乱的- -
debug 里面的样例输入和搜到的几个 AC 输出不太一样……迷
相关文章推荐
- UVa 657 The die is cast
- UVA - 657 The die is cast(二重dfs)
- uva 657 - The die is cast
- uva 657 The die is cast
- Uva 657 - The die is cast
- UVA 657 The die is cast
- UVa 657 - The die is cast
- uva 657 - The die is cast
- uva_657-The die is cast
- UVa 657 The die is cast(DFS)
- UVA 657 The die is cast
- uva 657 - The die is cast
- uva 657 The die is cast
- UVA 657 - The die is cast
- UVA 657 The die is cast
- uva 657 - The die is cast
- The die is cast - UVa 657 搜索
- UVA 657-The die is cast(双重BFS)
- The die is cast UVA 657
- uva 657 - The die is cast