ZOJ Problem Set - 3429 Cube Simulation
題目描述:
題目鏈接:ZOJ Problem Set - 3429 Cube Simulation
題目大意:
根據題目描述,模擬在空間中的6種操作。對應不同輸入執行對應的操作。
解題思路:
題目的關鍵點在於,value的值和X,Y,Z座標的轉化關係。將題目描述的一個三維數組,拆分爲
複雜度分析:
時間複雜度:
空間複雜度:
AC代碼:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <cctype>
#include <algorithm>
#include <cstdlib>
using namespace std;
const int maxn = 1010;
int x[maxn],y[maxn],z[maxn];
int X,Y,Z;
int value,a,b,c;
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 FIND()
{
scanf("%d" ,&value);
if(value > X*Y*Z)return;
value--;
c = value % Z;
value /= Z;
b = value % Y;
value /= Y;
a = value;
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);
}
void QUERY()
{
scanf("%d%d%d",&a,&b,&c);
value = x[a]*Y*Z+y[b]*Z+z[c]+1;
printf("%d\n",value);
}
int main()
{
char op[6];
while(scanf("%s",op) != EOF)
{
if(strcmp(op,"FILL") == 0) FILL();
else if(strcmp(op,"SWAP1") == 0) SWAP1();
else if(strcmp(op,"SWAP2") == 0) SWAP2();
else if(strcmp(op,"SWAP3") == 0) SWAP3();
else if(strcmp(op,"FIND") == 0) FIND();
else if(strcmp(op,"QUERY") == 0) QUERY();
}
return 0;
}