Eight2

博客围绕HDU3567八数码问题展开,介绍了问题描述、输入输出要求及样例。题解指出,该题需从给定输入串处理到给定输出串,采用映射方式预处理字符串,将输入串的X置0,其他数从1到8排列形成映射,预处理10种初始状态能到达的状态。

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

传送门HDU3567

描述

Eight-puzzle, which is also called “Nine grids”, comes from an old game.
In this game, you are given a 3 by 3 board and 8 tiles. The tiles are numbered from 1 to 8 and each covers a grid. As you see, there is a blank grid which can be represented as an ‘X’. Tiles in grids having a common edge with the blank grid can be moved into that blank grid. This operation leads to an exchange of ‘X’ with one tile.
We use the symbol ‘r’ to represent exchanging ‘X’ with the tile on its right side, and ‘l’ for the left side, ‘u’ for the one above it, ‘d’ for the one below it.
A state of the board can be represented by a string S using the rule showed below.
The problem is to operate an operation list of ‘r’, ‘u’, ‘l’, ‘d’ to turn the state of the board from state A to state B. You are required to find the result which meets the following constrains:

  1. It is of minimum length among all possible solutions.
  2. It is the lexicographically smallest one of all solutions of minimum length.

    输入

    The first line is T (T <= 200), which means the number of test cases of this problem.
    The input of each test case consists of two lines with state A occupying the first line and state B on the second line.
    It is guaranteed that there is an available solution from state A to B.

输出

For each test case two lines are expected.
The first line is in the format of “Case x: d”, in which x is the case number counted from one, d is the minimum length of operation list you need to turn A to B.
S is the operation list meeting the constraints and it should be showed on the second line.

样例

  • Input
    2
    12X453786
    12345678X
    564178X23
    7568X4123

  • Output
    Case 1: 2
    dd
    Case 2: 8
    urrulldr

题解

  • 题意:与上一题不一样的是,此题要求从给定输入串处理到给定输出串
  • 将字符串采用映射的方式进行预处理,然后O(t)查询,t为答案长度。
  • 将输入串的X置0,其他的数从1到8一次排列形成映射,则初始状态就只有10种,预处理这10中状态能到达的状态。
  • 对于样例中的564178X23,我们将其映射为123456078,则7568X4123就相应得被映射为512603478。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<bits/stdc++.h>
#define INIT(a,b) memset(a,b,sizeof(a))
#define LL long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=362885;
const int mod=1e9+7;
string ori[10]={"012345678","102345678","120345678","123045678","123405678",
"123450678","123456078","123456708","123456780"};
int rec[4]={3,-1,1,-3};
string ops="dlru";
int ans[10][N];
int pre[10][N];
int vis[10][N],fac[10];
int h[10];
struct node{
string sta;
int x;
};
int cantor(string a){
int ans=0,c=0;
for(int i=0;i<9;i++){
c=0;
for(int j=i+1;j<9;j++)
if(a[j]<a[i]) c++;
ans+=c*fac[9-i-1];
}
return ans;
}
bool judge(int x,int to){
if(to<0||to>=9)return false;
if((x==2&&to==3)||(x==3&&to==2))return false;
if((x==5&&to==6)||(x==6&&to==5))return false;
return true;
}
void bfs(int t){
queue<node> que;
int c=cantor(ori[t]);
vis[t][c]=0;
que.push((node){ori[t],t});
while(!que.empty()){
node q=que.front();que.pop();
c=cantor(q.sta);
for(int i=0;i<4;i++){
int to=q.x+rec[i];
if(judge(q.x,to)){
swap(q.sta[q.x],q.sta[to]);
int c1=cantor(q.sta);
if(vis[t][c1]==-1){
vis[t][c1]=vis[t][c]+1;
que.push((node){q.sta,to});
ans[t][c1]=i;
pre[t][c1]=c;
}
swap(q.sta[q.x],q.sta[to]);
}
}
}
}
void print(int n,int c){
if(pre[n][c]==-1) return ;
print(n,pre[n][c]);
printf("%c",ops[ans[n][c]]);
}
int main(){
//ios::sync_with_stdio(false);//不要关闭流同步,会wa
//cin.tie(0);
INIT(vis,-1);INIT(pre,-1);
fac[0]=1;
for(int i=1;i<10;i++)
fac[i]=fac[i-1]*i;
for(int i=0;i<9;i++) bfs(i);
int t,n;
cin>>t;
string s1,s2;
for(int _=1;_<=t;_++){
cout<<"Case "<<_<<": ";
cin>>s1>>s2;
int m=1;
for(int i=0;i<9;i++){
if(s1[i]=='X'){
n=i;
h[0]=0;
}
else h[s1[i]-'0']=m++;
}
string ss="123456789";
for(int i=0;i<9;i++){
if(s2[i]=='X') s2[i]='0';
ss[i]=h[s2[i]-'0']+'0';
}
int c=cantor(ss);
cout<<vis[n][c]<<endl;
print(n,c);
if(vis[n][c]!=-1)cout<<endl;
}
return 0;
}
### 配置八通道TDM模式 在电信通信中,当提到八通道TDM(Time Division Multiplexing)模式时,意味着存在八个不同的子信道共享同一物理线路来传输数据。每个子信道分配有一个固定的时隙用于发送其信息流[^1]。 对于配置8 channel TDM mode而言: - **帧结构**:每一完整的TDM帧包含了来自这八个不同源的数据样本,也就是每条子信道占用一个独特的time-slot。因此,在这种情况下,一整个周期内会依次排列着属于各个声道的时间片断。 - **同步机制**:为了确保接收端能够正确解析这些混合在一起的信息,发收双方必须保持严格的时钟同步。这意味着它们应该遵循相同的采样率以及相位关系以便于准确无误地分离出原始信号成分。 - **硬件需求**:实现这样的多路复用通常需要专门设计的设备支持,比如具有相应接口标准(如E1/T1等)的路由器或者交换机模块。这类装置内部集成了必要的逻辑电路用来处理输入/输出比特流并执行相应的编码解码操作。 ```python class TDMMultiplexer: def __init__(self, channels=8): self.channels = channels def multiplex(self, data_streams): """Multiplexes multiple input streams into a single output stream.""" frame = [] for i in range(len(data_streams[0])): for ch in range(self.channels): try: frame.append(data_streams[ch][i]) except IndexError: pass # Handle uneven lengths of input streams return frame tdm_mux = TDMMultiplexer(channels=8) data_streams = [ ['A', 'B'], ['C', 'D'], ['E', 'F'], ['G', 'H'], ['I', 'J'], ['K', 'L'], ['M', 'N'], ['O', 'P'] ] output_stream = tdm_mux.multiplex(data_streams) print(output_stream) ``` 此代码片段展示了如何创建一个多路复用器类`TDMMultiplexer`,它接受指定数量的通道作为参数初始化,并提供了一个方法`multiplex()`来进行实际的数据组合工作。这里假设所有传入的数据流长度相同;如果遇到不一致的情况,则简单跳过缺失部分而不引发错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值