comiz

2007年11月4日

a problem of maze

Problem Statement

People enjoy mazes, but they also get them dirty. Arrows, graffiti, and chewing gum are just a few of the souvenirs people leave on the walls. You, the maze keeper, are assigned to whiten the maze walls. Each face of the wall requires one liter of paint, but you are only required to paint visible faces. You are given a map of the maze, and you must determine the amount of paint needed for the job.

The maze is described by a vector <string> maze, where each character can be either '#' (a wall) or '.' (an empty space). All '.' characters on the perimeter of the map are considered entrances to the maze. Upon entering the maze, one can only move horizontally and vertically through empty spaces, and areas that are not reachable by these movements are not considered visible. Each '#' represents a square block with four wall faces (each side of the square is a face). A face is visible if it is not directly adjacent to another wall (and is in a reachable area of the maze). For example, two adjacent blocks can have at most six visible faces since two of their faces are directly adjacent to each other. All exterior faces on the perimeter are considered visible.

For example, the following picture represents a trivial maze with just one (wide) entrance and only four empty reachable spaces:

 TroytownKeeper.png

To whiten this maze you must paint the faces highlighted in yellow above: 16 for its perimeter, plus 8 interior faces. Note that there are faces that are not visible and thus need not be painted.

Definition     

Class: TroytownKeeper

Method: limeLiters Parameters: vector <string>

Returns: int

Method signature: int limeLiters(vector <string> maze)

(be sure your method is public)     

Constraints

- maze will contain between 1 and 50 elements, inclusive.

- Each element of maze will contain between 1 and 50 characters, inclusive.

- All elements of maze will have the same number of characters.

- All characters in maze will be either '.' or '#' . Examples 0)  

 

   

{"##..#",
"#.#.#",
"#.#.#",
"#####"}
Returns: 24

posted @ 2007-11-04 19:35 comiz 阅读(277) | 评论 (1)编辑 收藏

2007年10月24日

一道基础题

12,…,99个数分成三组,分别组成三个三位数,且使这三个三位数构成

   123的比例,试求出所有满足条件的三个三位数。

   例如:三个三位数192,384,576满足以上条件。
题目比较基础,自己用的回朔法,万里高楼平地起,慢慢来吧...
/* Note:Your choice is C IDE */
#define null 0
#include "stdio.h"
void inject(int N,int *nNum)
{
    int sum[3],i,j,k;
    if(N==0)
    {
        sum[0]=*nNum*100+*(nNum+1)*10+*(nNum+2);
        sum[1]=*(nNum+3)*100+*(nNum+4)*10+*(nNum+5);
        sum[2]=*(nNum+6)*100+*(nNum+7)*10+*(nNum+8);
        if(((sum[0]<<1)==sum[1])&&((3*sum[0])==sum[2]))
        {
            printf("we have one of them:");   
            printf("%d,%d,%d\n",sum[0],sum[1],sum[2]);
        }
    }
    else
    {
        for(j=0;j<9;j++)
        {
            if(*(nNum+j)==null)
            {
                *(nNum+j)=N;
                inject(N-1,nNum);
                *(nNum+j)=null;
            }
        }
    }
}
main()
{
    int k;
    int Num[9];
    for(k=0;k<9;k++)
    {
        Num[k]=null;   
    }
        inject(9,Num);
}

posted @ 2007-10-24 18:22 comiz 阅读(97) | 评论 (0)编辑 收藏

仅列出标题  
<2019年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(1)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜