博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
The block problem poj1208
阅读量:7297 次
发布时间:2019-06-30

本文共 2234 字,大约阅读时间需要 7 分钟。

POJ1208地址:

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 
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
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
no<<""; p=p->next; } cout<

转载地址:http://qdfnm.baihongyu.com/

你可能感兴趣的文章
Python--day61--Django中的app
查看>>
爬虫能做什么
查看>>
实现键盘录入的第二种方式。。。。。
查看>>
Spring基于 Annotation 的简单介绍
查看>>
【树型DP】加分二叉树
查看>>
我的 FPGA 学习历程(11)—— 实验:按键消抖
查看>>
IOS中实现设备摇动检测
查看>>
UOJ#449. 【集训队作业2018】喂鸽子
查看>>
Android-6步教你自定义View
查看>>
Spring MVC 返回视图时添加的模型数据------POJO
查看>>
设置 JAVA_HOME
查看>>
POJ-1201 Intervals---差分约束
查看>>
trigger自动执行事件
查看>>
在Visual Studio 2010 里使用Nunit 进行Debug 测试
查看>>
[转]android使用shape stroke描边只保留底部
查看>>
[LeetCode] Binary Tree Zigzag Level Order Traversal
查看>>
js面向对象小结(工厂模式,构造函数,原型方法,继承)
查看>>
C# list介绍
查看>>
jQuery Ajax全解析
查看>>
利用 T-sql 的从句 for xml path('') 实现多行合并到一行, 并带有分隔符
查看>>