POJ1208地址:http://poj.org/problem?id=1208

move a onto b :先将a和b上的其他木块移回到它们的初始位置,然后将木块a摞在木块b上.
move a over b :先将木块a上的其他木块移到它们的初始位置后,然后将木块a摞到包含了木块b的那一堆木块上面
pile a onto b :先将木块b上的所有木块移回到它们的初始位置,然后将木块a及其上的木块移到木块b上.
pile a over b :将包含木块a的那一摞木块移到包含了木块b的那一堆木块上面.
#include <iostream>using namespace std;

struct Node{int no;struct Node *next;};struct Node *station[25];int Bplace[25];

void Init(int n){for(int i=0;i<n;i++){        station[i]=(struct Node*)malloc(sizeof(struct Node));         station[i]->no=i;          Bplace[i]=i;          station[i]->next=NULL;    }}struct Node *Find(int a,bool setNULL){int b;struct Node *p,*q;       b=Bplace[a];if(station[b]->no==a)       {          p=station[b];if(setNULL){             station[b]=NULL;          }return p;       }else{          q=station[b];          p=q->next;while(p->no!=a){             q=p;             p=p->next;          }if(setNULL)             q->next=NULL;return p;       }}

void f(int a){struct Node *p;    p=Find(a,false);  //constant point to the station[a->no]    if(p->next==NULL)return;int j;while(p->next!=NULL){      j=p->next->no;      station[j]=p->next;      Bplace[j]=j;      p->next=NULL;      p=station[j];    }}

void move(int a,int b){if(a==b || Bplace[a]==Bplace[b])return;struct Node *pa,*pb;       pa=Find(a,true);       pb=Find(b,false);while(pb->next){          pb=pb->next;       }       pb->next=pa;while(pa!=NULL){          Bplace[pa->no]=Bplace[pb->no];          pa=pa->next;       }}

void monto(int a,int b){    f(a);    f(b);    move(a,b);}void mover(int a,int b){  f(a);  move(a,b);}void ponto(int a,int b){    f(b);    move(a,b);}void pover(int a,int b){  move(a,b);}

int main(){int n,a,b;struct Node *p;char ch1[5],ch2[5];//freopen("acm.txt","r",stdin);    cin>>n;    Init(n);while(cin>>ch1 && strcmp(ch1,"quit")!=0){       cin>>a;       cin>>ch2;       cin>>b;if(strcmp(ch1,"move")==0){if(strcmp(ch2,"onto")==0)               monto(a,b);else               mover(a,b);       }else{if(strcmp(ch2,"onto")==0)             ponto(a,b);else              pover(a,b);

       }    }//while    for(int i=0;i<n;i++)    {       cout<<i<<": ";       p=station[i];while(p!=NULL)       {        cout<<p->no<<"";        p=p->next;       }       cout<<endl;    }return 0;}

转载于:https://www.cnblogs.com/Jason-Damon/archive/2011/11/24/2261354.html

The block problem poj1208相关推荐

  1. Uva 101 the block problem 木块问题(算法竞赛经典入门)STL vector

    Uva 101 the block problem 木块问题 题目大意: 输入n,得到编号为0~n-1的木块,分别摆放在顺序排列编号为0~n-1的位置.现对这些木块进行操作,操作分为四种. 1.mov ...

  2. 区块链和区块链联盟_您可能对区块链有误解。 让我来帮助您修复它们。

    区块链和区块链联盟 by Syed Fazle Rahman 赛义德·法兹勒·拉曼(Syed Fazle Rahman) 您可能对区块链有误解. 让我来帮助您修复它们. (You might have ...

  3. HCIE-Cloud笔试

    前言: 目录按照HCIE-Cloud官方培训教材V2.0进行制定,通过笔试考点挂钩HCIE-Cloud官方培训教材V2.0中的知识,相互强化记忆 1.优点:基本笔试的知识分类,是按照该教材的目录大纲分 ...

  4. hive日常报错之 serious problem serious problem,block 丢失

    2019独角兽企业重金招聘Python工程师标准>>> https://community.hortonworks.com/questions/71589/after-upgradi ...

  5. vim block vim_如何不再害怕Vim

    vim block vim 精选最流行的命令以及如何使用它们 (A curation of the most popular commands and how to use them) If you' ...

  6. linux如何关闭udp端口,如何阻止linux RHEL7中的udp端口范围(How to block udp ports range in linux RHEL7)...

    如何阻止linux RHEL7中的udp端口范围(How to block udp ports range in linux RHEL7) 需要测试使用UDP端口范围从5000到60,000英寸的应用 ...

  7. knight tour java_The Knight’s tour problem

    Backtracking | Set 1 (The Knight's tour problem骑士周游算法 ) Backtracking is an algorithmic paradigm that ...

  8. Entity Framework Unit Testing problem and solution(转)

    其实下文中说的解决方案不仅仅适用于应用了Ef的项目,其它涉及数据访问的测试同样适用. 不说先贴上原文链接 : (一) http://graemehill.ca/unit-testing-an-enti ...

  9. Paper:《How far are we from solving the 2D 3D Face Alignment problem? 》解读与翻译

    Paper:<How far are we from solving the 2D & 3D Face Alignment problem? >解读与翻译 目录 How far a ...

  10. verilog for循环_HDLBits:在线学习 Verilog (二十四 · Problem 115-119)

    本系列文章将和读者一起巡礼数字逻辑在线学习网站 HDLBits 的教程与习题,并附上解答和一些作者个人的理解,相信无论是想 7 分钟精通 Verilog,还是对 Verilog 和数电知识查漏补缺的同 ...

最新文章

  1. linux基础-网络基础知识篇
  2. 建立可扩展的silverlight应用框架
  3. UA MATH564 概率论 QE练习题1
  4. 如何通过编程方式添加Native Client服务器别名
  5. Android APK 签名文件MANIFEST.MF、CERT.SF、CERT.RSA分析
  6. Spring Cloud配置–外部化应用程序配置
  7. index.wxss 导入不显示结果
  8. 从矩阵分解到FM的演进、FM如何用于召回和排序以及实现说明
  9. NeatUpload——支持大文件上传的控件
  10. Pytorch 微积分
  11. 记一个tcp udp测试工具ethrc
  12. 从Unity导出Obj格式的地形(Terrian)
  13. linux 腾达驱动程序,腾达(Tenda)-U12 Linux系统如何安装驱动
  14. 全国计算机联合考试广西二级c语言近五年试题,计算机二级c语言试题
  15. Enzo Life Sciences/艾美捷丨线粒体/胞浆分离试剂盒
  16. 学田岛电脑绣花制版新人上手教程之一
  17. 01-vue(v-text,插值语法,v-html,v-model,v-on,v-bind,vue中的this,事件按键修饰符)
  18. 今日头条广告如何优化?这四个思路至关重要
  19. 加解密篇 - 什么是加密加盐 (分析web3j的加盐处理)
  20. Matlab绘图------特殊图形------直方图

热门文章

  1. 接口与继承:不允许继承的类
  2. Oracle 12C -- 不同容器之间切换
  3. mysql索引操作(转)
  4. 如果创建表提示数据库已经存在该对象,那该怎么办
  5. 邱锡鹏:为什么相比于CV,NLP领域的发展要缓慢?
  6. 打开你的脑洞:NER如何进行数据增强 ?
  7. PyTorch中文版官方教程来了,附pdf下载
  8. 【论文】使用bilstm在中文分词上的SOTA模型
  9. 掌握这些的Linux命令,你基本稳了
  10. numpy—np.argpartition