Cube Simulation zoj3429 模拟

本文介绍了一种使用三维数组模拟特定操作的方法,包括填充、交换和查找等操作,并通过示例输入输出展示了整个过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

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
Hint

exchange(x,y) means exchange the value of variable x and y.

Because of HUGE input and output, scanf and printf is recommended.

(1)题意:给一些操作函数,问一定数量的操作给出,会输出什么。
解法:因为code3维数组,实际作用是计数器,所以给出x,y,z的值可以直接得出3维数组所代表的数组的值。即Value=tx[a]*Y*Z+ty[b]*Z+tz[c]+1;而其他操作,交换也是相当于是交换坐标,给出value,也可以模拟得出x,y,z的值。

tx,ty,tz数组分别模拟x,y,z的坐标值。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int X,Y,Z;
int tx[1005],ty[1005],tz[1005];
void FILL()
{
    puts("START");
    int i,j,k;
    for (i = 0; i < X; i++) tx[i]=i;
    for (j = 0; j < Y; j++) ty[j]=j;
    for (k = 0; k < Z; k++) tz[k]=k;
}
void SWAP1(int x1,int x2)
{
    swap(tx[x1],tx[x2]);
}
void SWAP2(int y1,int y2)
{
    swap(ty[y1],ty[y2]);
}
void SWAP3(int z1,int z2)
{
    swap(tz[z1],tz[z2]);
}
void FIND(int value)
{
    value--;            
    int ttz=value%Z;
    value=value/Z;      
    int tty=value%Y;
    value=value/Y;     
    int ttx=value;

    int i,j,k,p;
    for(p=0;p<X;p++)
    {
        if(tx[p]==ttx)
        {
            i=p;
            break;
        }
    }
    for(p=0;p<Y;p++)
    {
        if(ty[p]==tty)
        {
            j=p;
            break;
        }
    }
    for(p=0;p<Z;p++)
    {
        if(tz[p]==ttz)
        {
            k=p;
            break;
        }
    }
    if(i<X&&j<Y&&k<Z) printf("%d %d %d\n",i,j,k);
}
void QUERY(int a,int b,int c)
{
    int fuck=tx[a]*Y*Z+ty[b]*Z+tz[c]+1;
    printf("%d\n",fuck);
}
int main()
{
    char a[20];
    while(scanf("%s",a)!=EOF)
    {
        int i;
        if(strcmp(a,"FILL")==0)
        {
            scanf("%d %d %d",&X,&Y,&Z);
            FILL();
        }
        else if(strcmp(a,"SWAP1")==0)
        {
            int x1,x2;
            scanf("%d %d",&x1,&x2);
            SWAP1(x1,x2);
        }
       else if(strcmp(a,"SWAP2")==0)
        {
            int y1,y2;
            scanf("%d %d",&y1,&y2);
            SWAP2(y1,y2);
        }
        else if(strcmp(a,"SWAP3")==0)
        {
            int z1,z2;
            scanf("%d %d",&z1,&z2);
            SWAP3(z1,z2);
        }
        else if(strcmp(a,"FIND")==0)
        {
            int value;
            scanf("%d",&value);
            FIND(value);
        }
        else if(strcmp(a,"QUERY")==0)
        {
            int x,y,z;
            scanf("%d %d %d",&x,&y,&z);
            QUERY(x,y,z);
        }
    }
    return 0;
}
【基于QT的调色板】是一个使用Qt框架开发的色彩选择工具,类似于Windows操作系统中常见的颜色选取器。Qt是一个跨平台的应用程序开发框架,广泛应用于桌面、移动和嵌入式设备,支持C++和QML语言。这个调色板功能提供了横竖两种渐变模式,用户可以方便地选取所需的颜色值。 在Qt中,调色板(QPalette)是一个关键的类,用于管理应用程序的视觉样式。QPalette包含了一系列的颜色角色,如背景色、前景色、文本色、高亮色等,这些颜色可以根据用户的系统设置或应用程序的需求进行定制。通过自定义QPalette,开发者可以创建具有独特视觉风格的应用程序。 该调色板功能可能使用了QColorDialog,这是一个标准的Qt对话框,允许用户选择颜色。QColorDialog提供了一种简单的方式来获取用户的颜色选择,通常包括一个调色板界面,用户可以通过滑动或点击来选择RGB、HSV或其他色彩模型中的颜色。 横渐变取色可能通过QGradient实现,QGradient允许开发者创建线性或径向的色彩渐变。线性渐变(QLinearGradient)沿直线从一个点到另一个点过渡颜色,而径向渐变(QRadialGradient)则以圆心为中心向外扩散颜色。在调色板中,用户可能可以通过滑动条或鼠标拖动来改变渐变的位置,从而选取不同位置的颜色。 竖渐变取色则可能是通过调整QGradient的方向来实现的,将原本水平的渐变方向改为垂直。这种设计可以提供另一种方式来探索颜色空间,使得选取颜色更为直观和便捷。 在【colorpanelhsb】这个文件名中,我们可以推测这是与HSB(色相、饱和度、亮度)色彩模型相关的代码或资源。HSB模型是另一种常见且直观的颜色表示方式,与RGB或CMYK模型不同,它以人的感知为基础,更容易理解。在这个调色板中,用户可能可以通过调整H、S、B三个参数来选取所需的颜色。 基于QT的调色板是一个利用Qt框架和其提供的色彩管理工具,如QPalette、QColorDialog、QGradient等,构建的交互式颜色选择组件。它不仅提供了横竖渐变的色彩选取方式,还可能支持HSB色彩模型,使得用户在开发图形用户界面时能更加灵活和精准地控制色彩。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值