Description
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.
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
exchange(x,y) means exchange the value of variable x and y.
Because of HUGE input and output, scanf and printf is recommended.
个人认为一道还不错的模拟题,题意就是给你一堆的函数,然后变换啊,交换数值啊,最后再查询出来就OK了。其实我就是抽象成了一个函数,一个三维立体的函数(三次方?),我也不知道如何解释,然后求解这个函数变得到了结果啊,其实很简单很简单很简单,带入个点从头开始设就知道函数是什么了
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxx=1010; int x[maxx],y[maxx],z[maxx]; int X,Y,Z; void FILL() { scanf("%d%d%d",&X,&Y,&Z); puts("START"); for(int i=0;i<X;i++) x[i]=i; for(int i=0;i<Y;i++) y[i]=i; for(int i=0;i<Z;i++) z[i]=i; } void SWAP1() { int x1,x2; scanf("%d%d",&x1,&x2); swap(x[x1],x[x2]); } void SWAP2() { int y1,y2; scanf("%d%d",&y1,&y2); swap(y[y1],y[y2]); } void SWAP3() { int z1,z2; scanf("%d%d",&z1,&z2); swap(z[z1],z[z2]); } void QUERY() { int value,a,b,c; scanf("%d%d%d",&a,&b,&c); value=x[a]*Y*Z+y[b]*Z+z[c]+1; printf("%d\n",value); } void FIND() { int w,a,b,c; scanf("%d",&w); if(w>X*Y*Z) return ; w--; c=w%Z; w/=Z; b=w%Y; w/=Y; a=w; for(int i=0;i<X;i++) { if(x[i]==a) { a=i; break; } } for(int i=0;i<Y;i++) { if(y[i]==b) { b=i; break; } } for(int i=0;i<Z;i++) { if(z[i]==c) { c=i; break; } } printf("%d %d %d\n",a,b,c); } int main() { char str[10]; while(scanf("%s",str)!=EOF) { if(strcmp(str,"FILL")==0) FILL(); else if(strcmp(str,"SWAP1")==0) SWAP1(); else if(strcmp(str,"SWAP2")==0) SWAP2(); else if(strcmp(str,"SWAP3")==0) SWAP3(); else if(strcmp(str,"FIND")==0) FIND(); else if(strcmp(str,"QUERY")==0) QUERY(); } return 0; }