编程介的小学生 2017-08-29 09:12 采纳率: 20.5%
浏览 648
已采纳

Cube Simulation

Here's a cube whose size of its 3 dimensions are all infinite. Meanwhile, there're 6 programs operating this cube:

FILL(X,Y,Z): Fill some part of the cube with different values.

memset(cube, 0, sizeof(cube));
puts("START");
cnt = 0;
for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
        for (int k = 0; k < Z; k++) {
            cube[i][j][k] = ++cnt;
        }
    }
}

SWAP1(x1,x2): Swap two sub-cube along the first dimensions.

for (int j = 0; j < Y; j++) {
    for (int k = 0; k < Z; k++) {
        exchange(cube[x1][j][k], cube[x2][j][k]);
    }
}

SWAP2(y1,y2): Swap two sub-cube along the second dimensions.

for (int i = 0; i < X; i++) {
    for (int k = 0; k < Z; k++) {
        exchange(cube[i][y1][k], cube[i][y2][k]);
    }
}

SWAP3(z1,z2): Swap two sub-cube along the third dimensions.

for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
        exchange(cube[i][j][z1], cube[i][j][z2]);
    }
}

FIND(value): Output the value's location, if it exist.

for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
        for (int k = 0; k < Z; k++) {
            if (cube[i][j][k] == value) {
                printf("%d %d %d\n", i, j, k);
            }
        }
    }
}

QUERY(x,y,z): Output the value at (x,y,z).

printf("%d\n", cube[x][y][z]);

We'll give a list of operations mentioned above. Your job is to simulate the program and tell us what does the machine output in progress.

Input

There'll be 6 kind of operations in the input.

FILL X Y Z (1 <= X, Y, Z <= 1000) for FILL(X,Y,Z)
SWAP1 X1 X2 (0 <= X1, X2 < X) for SWAP1(X1,X2)
SWAP2 Y1 Y2 (0 <= Y1, Y2 < Y) for SWAP2(Y1,Y2)
SWAP3 Z1 Z2 (0 <= Z1, Z2 < Z) for SWAP3(Z1,Z2)
FIND value (value > 0) for FIND(value)
QUERY x y z (0 <= x < X, 0 <= y < Y, 0 <= z < Z) for QUERY(x,y,z)
The input will always start with FILL operation and terminate by EOF.

The number of the operations will less than 200,000, while the FILL operation will less than 100.

Output

Simulate all of the operations in order, and print the output of the programs.

Sample Input

FILL 2 3 1
SWAP1 0 1
SWAP2 0 2
SWAP3 0 0
FIND 1
FIND 2
FIND 3
FIND 4
FIND 5
FIND 6
FIND 7
QUERY 0 0 0
QUERY 0 1 0
QUERY 0 2 0
QUERY 1 0 0
QUERY 1 1 0
QUERY 1 2 0
Sample Output

START
1 2 0
1 1 0
1 0 0
0 2 0
0 1 0
0 0 0
6
5
4
3
2
1

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-13 00:29
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制