The block problem poj1208
POJ1208地址:http://poj.org/problem?id=1208
#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相关推荐
- Uva 101 the block problem 木块问题(算法竞赛经典入门)STL vector
Uva 101 the block problem 木块问题 题目大意: 输入n,得到编号为0~n-1的木块,分别摆放在顺序排列编号为0~n-1的位置.现对这些木块进行操作,操作分为四种. 1.mov ...
- 区块链和区块链联盟_您可能对区块链有误解。 让我来帮助您修复它们。
区块链和区块链联盟 by Syed Fazle Rahman 赛义德·法兹勒·拉曼(Syed Fazle Rahman) 您可能对区块链有误解. 让我来帮助您修复它们. (You might have ...
- HCIE-Cloud笔试
前言: 目录按照HCIE-Cloud官方培训教材V2.0进行制定,通过笔试考点挂钩HCIE-Cloud官方培训教材V2.0中的知识,相互强化记忆 1.优点:基本笔试的知识分类,是按照该教材的目录大纲分 ...
- hive日常报错之 serious problem serious problem,block 丢失
2019独角兽企业重金招聘Python工程师标准>>> https://community.hortonworks.com/questions/71589/after-upgradi ...
- vim block vim_如何不再害怕Vim
vim block vim 精选最流行的命令以及如何使用它们 (A curation of the most popular commands and how to use them) If you' ...
- 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英寸的应用 ...
- knight tour java_The Knight’s tour problem
Backtracking | Set 1 (The Knight's tour problem骑士周游算法 ) Backtracking is an algorithmic paradigm that ...
- Entity Framework Unit Testing problem and solution(转)
其实下文中说的解决方案不仅仅适用于应用了Ef的项目,其它涉及数据访问的测试同样适用. 不说先贴上原文链接 : (一) http://graemehill.ca/unit-testing-an-enti ...
- 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 ...
- verilog for循环_HDLBits:在线学习 Verilog (二十四 · Problem 115-119)
本系列文章将和读者一起巡礼数字逻辑在线学习网站 HDLBits 的教程与习题,并附上解答和一些作者个人的理解,相信无论是想 7 分钟精通 Verilog,还是对 Verilog 和数电知识查漏补缺的同 ...
最新文章
- linux基础-网络基础知识篇
- 建立可扩展的silverlight应用框架
- UA MATH564 概率论 QE练习题1
- 如何通过编程方式添加Native Client服务器别名
- Android APK 签名文件MANIFEST.MF、CERT.SF、CERT.RSA分析
- Spring Cloud配置–外部化应用程序配置
- index.wxss 导入不显示结果
- 从矩阵分解到FM的演进、FM如何用于召回和排序以及实现说明
- NeatUpload——支持大文件上传的控件
- Pytorch 微积分
- 记一个tcp udp测试工具ethrc
- 从Unity导出Obj格式的地形(Terrian)
- linux 腾达驱动程序,腾达(Tenda)-U12 Linux系统如何安装驱动
- 全国计算机联合考试广西二级c语言近五年试题,计算机二级c语言试题
- Enzo Life Sciences/艾美捷丨线粒体/胞浆分离试剂盒
- 学田岛电脑绣花制版新人上手教程之一
- 01-vue(v-text,插值语法,v-html,v-model,v-on,v-bind,vue中的this,事件按键修饰符)
- 今日头条广告如何优化?这四个思路至关重要
- 加解密篇 - 什么是加密加盐 (分析web3j的加盐处理)
- Matlab绘图------特殊图形------直方图