AOJ664 彩灯高高挂

来源:互联网 发布:linux 解包 编辑:程序博客网 时间:2024/04/26 17:31

Description
Bran收到了好友的一个礼物——彩灯。彩灯是一个n×n×n的正方体,由n×n×n个小正方体组成,每个小正方体都是一个小彩灯。我们用坐标(x,y,z)(0≤x,y,z<n)来表示各个小彩灯,那么有彩灯(x,y,z)与彩灯(x-1,y,z),(x+1,y,z),(x,y-1,z),(x,y+1,z),(x,y,z-1),(x,y,z+1)们相邻(如果这些彩灯坐标合法的话)。初始时,有些小彩灯是亮着的,并有各自的颜色,颜色用正整数表示。之后的每一秒,对于所有关着的小彩灯,如果它与某个开着的小彩灯相邻,那么关着的小灯就会开启,并且灯的颜色与这个灯的相同;如果与多个亮着的灯相邻,那么灯的颜色为那些开着的邻灯中值最小的一个。
如此,一定时间后,所有的小彩灯都会亮起来,请求出各个小彩灯的颜色。


Input
第1行:测试数据组数t;
接下来依次是这t组数据,对于每一组数据:
第1行:n m;n含义如上,m表示初始时亮着的小彩灯数量,有1≤n≤40,且1≤m≤n3
接下来的m行中,第i(1≤i≤m)行为三个整数x y z,表示小彩灯(x,y,z)初始时是亮的,且颜色是i,保证有0≤x,y,z<n;
第n+2行:空行。

Output
一组测试数据占一行,对于每组测试数据:
输出m个数,第i个数表示颜色为i的小彩灯的数量,这m个数之间用单个空格两亮隔开,具体参考输入输出样例。

Sample Input
OriginalTransformed
32 80 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 13 11 1 15 40 2 42 0 03 4 44 1 2

Sample Output
OriginalTransformed
1 1 1 1 1 1 12738 28 32 27


第六届网络赛 E题

/***********************************************************************************************************************题意:略思路:三维BFS 膜拜cxlove的精简的代码 让我收获很多 Orz....***********************************************************************************************************************/#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <ctime>using namespace std;int n , m , a[50][50][50] , c[50] , way[6][3] = {{-1 , 0 , 0} , {1 , 0 , 0} , {0 , -1 , 0} , {0 ,1 , 0} , {0 , 0 , -1} , {0 , 0 , 1}};typedef struct{int x , y , z , cl;}node;queue<node> q;void bfs(){while(!q.empty()){node u = q.front();for(int i = 0 ; i < 6 ; i ++){node v; v.x = u.x + way[i][0] ; v.y = u.y + way[i][1] ; v.z = u.z + way[i][2];if(v.x >= 0 && v.y >= 0 && v.z >= 0 && v.x < n && v.y < n && v.z < n && !a[v.x][v.y][v.z]){a[v.x][v.y][v.z] = u.cl;v.cl = u.cl;c[u.cl] ++;q.push(v);}}q.pop();}}int main(){//freopen("data.in" , "r" , stdin);int t; scanf("%d" , &t);while(t--){memset(a , 0 , sizeof(a));while(!q.empty()) q.pop();scanf("%d%d" , &n , &m);for(int i = 1 ; i <= m ; i ++){node temp;scanf("%d%d%d" , &temp.x , &temp.y , &temp.z);temp.cl = i;c[i] = 1;a[temp.x][temp.y][temp.z] = i;q.push(temp);}bfs();for(int i = 1 ; i <= m ; i ++) printf("%d%s" , c[i] , (i == m) ? "\n" : " ");}return 0;}






0 0
原创粉丝点击