UVa 657:the die is cast search topic

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.