uva 10795 - A Different Task(递推,3级)

本文探讨了经典的汉诺塔问题的一种变体,即初始状态下圆盘可以位于任意柱子上的情况。通过递归方法计算从一种配置转换到另一种所需最小移动次数。

  A Different Task 

\epsfbox{p10795a.eps}

The (Three peg) Tower of Hanoi problem is a popular one in computer science. Briefly the problem is to transfer all the disks from peg-A to peg-C using peg-B as intermediate one in such a way that at no stage a larger disk is above a smaller disk. Normally, we want the minimum number of moves required for this task. The problem is used as an ideal example for learning recursion. It is so well studied that one can find the sequence of moves for smaller number of disks such as 3 or 4. A trivial computer program can find the case of large number of disks also.


Here we have made your task little bit difficult by making the problem more flexible. Here the disks can be in any peg initially.

\epsfbox{p10795b.eps}

If more than one disk is in a certain peg, then they will be in a valid arrangement (larger disk will not be on smaller ones). We will give you two such arrangements of disks. You will have to find out the minimum number of moves, which will transform the first arrangement into the second one. Of course you always have to maintain the constraint that smaller disks must be upon the larger ones.

Input 

The input file contains at most 100 test cases. Each test case starts with a positive integer N ( 1$ \le$N$ \le$60), which means the number of disks. You will be given the arrangements in next two lines. Each arrangement will be represented by N integers, which are 12 or 3. If the i-th ( 1$ \le$i$ \le$N) integer is 1, you should consider that i-th disk is on Peg-A. Input is terminated by N = 0. This case should not be processed.

Output 

Output of each test case should consist of a line starting with `Case #' where # is the test case number. It should be followed by the minimum number of moves as specified in the problem statement.

Sample Input 

3
1 1 1
2 2 2
3
1 2 3
3 2 1
4
1 1 1 1
1 1 1 1
0

Sample Output 

Case 1: 7
Case 2: 3
Case 3: 0



Problem setter: Md. Kamruzzaman
Special Thanks: Derek Kisman (Alternate Solution), Shahriar Manzoor (Picture Drawing)

Miguel Revilla 2004-12-10

思路:汉诺塔可逆,所以A->B+C->B等价于A->C 如果过程中肯定需要B的话。

           F(f,num,where) f是状态序列,num为第几个,where 为 状态序列中第num个应该在哪。

           如果f[num]==where   F(f,num,where)等价于 F(f,num-1,where)

           否则就将其搬到合适状态。需要2^(num-1) 汉诺塔结论

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int mm=64;
int f[mm],t[mm];
long long go(int*f,int num,int where)
{
  if(num<=0)return 0;///已经完毕
  if(f[num]==where)return go(f,num-1,where);///相同,不动,继续考察上一块
  return go(f,num-1,6-where-f[num])+(1LL<<(num-1));///2^num-1,移一次的代价
}
int main()
{ int n;int cas=0;
  while(scanf("%d",&n)&&n)
  {
    for(int i=1;i<=n;++i)scanf("%d",&f[i]);
    for(int i=1;i<=n;++i)scanf("%d",&t[i]);
    int num=n;
    while(f[num]==t[num]&&num>=1)--num;///符合条件的最大块不动
    long long ans=0;
    if(num<1)goto out;
    ///因为搬动可逆,所以A->B +C->B == A->C 步骤数
    ///将前num-1块移走,然后调整最大块
        ans=go(f,num-1,6-f[num]-t[num])+go(t,num-1,6-t[num]-f[num])+1L;
  out:  printf("Case %d: %lld\n",++cas,ans);
  }
}

             

 


【评估多目标跟踪方法】9个高度敏捷目标在编队中的轨迹和测量研究(Matlab代码实现)内容概要:本文围绕“评估多目标跟踪方法”,重点研究9个高度敏捷目标在编队飞行中的轨迹生成与测量过程,并提供完整的Matlab代码实现。文中详细模拟了目标的动态行为、运动约束及编队结构,通过仿真获取目标的状态信息与观测数据,用于验证和比较不同多目标跟踪算法的性能。研究内容涵盖轨迹建模、噪声处理、传感器测量模拟以及数据可视化等关键技术环节,旨在为雷达、无人机编队、自动驾驶等领域的多目标跟踪系统提供可复现的测试基准。; 适合人群:具备一定Matlab编程基础,从事控制工程、自动化、航空航天、智能交通或人工智能等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于多目标跟踪算法(如卡尔曼滤波、粒子滤波、GM-CPHD等)的性能评估与对比实验;②作为无人机编队、空中交通监控等应用场景下的轨迹仿真与传感器数据分析的教学与研究平台;③支持对高度机动目标在复杂编队下的可观测性与跟踪精度进行深入分析。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注轨迹生成逻辑与测量模型构建部分,可通过修改目标数量、运动参数或噪声水平来拓展实验场景,进一步提升对多目标跟踪系统设计与评估的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值