Topic Link:
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=105&page=show_ problem&problem=598
Topic Type: Search
Sample input:
.............. ...
.
....... ..............................
...............*..............
...*****......****............
... *x***.....**x***
....... ... *****....***x**
........ ... ***x*.....****
......... ...*****.......*..............
..............................
........***........******.....
... **x****.....*x**x*
...... ......*******......******.....
... ****x**.......*x**x*
..... ........***........******.....
..............................
0 0
Sample output:
Throw 1
1 2 2 4
Analysis:
This problem can be said to be UVA 572-oil deposits version, first find out the area of the dice, and then in the dice area and then search inside the number of connected points.
In this way, you can use nested search methods to get the solution. It's OK to use DFS,BFS here.
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vec
Tor> using namespace std;
Char map[60][60];
int vis[60][60];
int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int W,h,dienum, dotnum;
struct Node{int x,y;
Node que[100000];
This search is used to count the number of connected points in the dice/deep search and wide search can be void bfs (int x, int y) {int front=0, rear=1;
que[0].x = x, que[0].y = y;
while (front < rear) {Node t = que[front++];
for (int i=0; i<4; ++i) {int dx=t.x+dir[i][0], dy=t.y+dir[i][1];
if (map[dx][dy]== ' * | | | map[dx][dy]== '. ') continue; if (dx>=0 && dx