poj 1096 & zoj 1063 Space Station Shielding (搜索 floodfill )

Space Station Shielding
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1342   Accepted: 477

Description

Roger Wilco is in charge of the design of a low orbiting space station for the planet Mars. To simplify construction, the station is made up of a series of Airtight Cubical Modules (ACM's), which are connected together once in space. One problem that concerns Roger is that of (potentially) lethal bacteria that may reside in the upper atmosphere of Mars. Since the station will occasionally fly through the upper atmosphere, it is imperative that extra shielding be used on all faces of the ACM's touch, either edge to edge or face to face, that joint is sealed so no bacteria can sneak through. Any face of an ACM shared by another ACM will not need shielding, of course, nor will a face which cannot be reached from the outside. Roger could just put extra shielding on all of the faces of every ACM, but the cost would be prohibitive. Therefore, he wants to know the exact number of ACM faces which need the extra shielding. 

Input

Input consists of multiple problem instances. Each instance consists of a specification of a space station. We assume that each space station can fit into an n x m x k grid (1 <= n, m, k <= 60), where each grid cube may or may not contain an ACM. We number the grid cubes 0, 1, 2, ..., kmn-1 as shown in the diagram below. Each space station specification then consists of the following: the first line contains four positive integers n m k l, where n, m and k are as described above and l is the number of ACM's in the station. This is followed by a set of lines which specify the l grid locations of the ACM's. Each of these lines contain 10 integers (except possibly the last). Each space station is fully connected (i.e., an astronaut can move from one ACM to any other ACM in the station without leaving the station). Values of n = m = k = l = 0 terminate input. 
poj 1096 & zoj 1063 Space Station Shielding (搜索 floodfill )_第1张图片

Output

For each problem instance, you should output one line of the form 

The number of faces needing shielding is s.

Sample Input

2 2 1 3
0 1 3
3 3 3 26
0 1 2 3 4 5 6 7 8 9
10 11 12 14 15 16 17 18 19 20
21 22 23 24 25 26
0 0 0 0

Sample Output

The number of faces needing shielding is 14.
The number of faces needing shielding is 54.

Source

East Central North America 2001


题意:

可以理解为把给你的这些方块放入水里,会浸到多少个面。


思路:

沿外围扫描进去,把外面的全部能标记上,然后依次访问每个方块的6个面,如果通过这个面到达的方块访问了则可浸到,ans++。


感想:

被按照x、y、z优先的顺序坑了好久。。。


代码:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 65
#define MAXN 200005
#define mod 1000000007
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 0.000001
typedef long long ll;
using namespace std;

int n,m,ans,cnt,tot,flag;
int h,k;
struct Node
{
    int x,y,z;
}now,cur;
vectora;
int dx[]={0,0,0,0,1,-1};
int dy[]={0,0,-1,1,0,0};
int dz[]={1,-1,0,0,0,0};
bool vis[maxn][maxn][maxn];
bool out[maxn][maxn][maxn];

bool isok(int x,int y,int z)
{
    if(x>=0&&x=0&&y=0&&z=n||ty<0||ty>=m||tz<0||tz>=h)
            {
                if(tx==-1||tx==n||ty==-1||ty==m||tz==-1||tz==h) ans++;
                continue ;
            }
            if(out[tx][ty][tz]) ans++;
        }
    }
}
int main()
{
    int i,j,t;
    int x,y,z;
    while(~scanf("%d%d%d%d",&n,&m,&h,&k))
    {
        if(!(n||m||h||k)) break ;
        a.clear();
        memset(vis,0,sizeof(vis));
        for(i=1;i<=k;i++)
        {
            scanf("%d",&t);
            z=t/(n*m);
            int u=t-n*m*z;
            y=u/n;
            x=u%n;
            vis[x][y][z]=1;
            cur.x=x,cur.y=y,cur.z=z;
            a.push_back(cur);
        }
        solve();
        printf("The number of faces needing shielding is %d.\n",ans);
    }
    return 0;
}





你可能感兴趣的:(搜索)