http://poj.org/problem?id=1208

晚点仔细看

https://blog.csdn.net/yxz8102/article/details/53098575

 #include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const long long N=1e9+;
#define LL long long
vector<int> pile[];
int n; //查找木块a所在的pile和height
void find_block(int a,int &p,int &h) //引用,相当于直接用实参
{
for(p=;p<n;p++)
{
for(h=;h<pile[p].size();h++)
{
if(pile[p][h]==a) return;
//vector就像一个二维数组,只是第一维大小固定(30),二维大小不固定。
}
}
}
//把p堆高度为h的木块上方所有的木块移回原位置
void clear_above(int p,int h)
{
for(int i=h+;i<pile[p].size();i++)
{
int t=pile[p][i];
pile[t].push_back(t); ////把标号为t的木块放回原位,即t堆
}
pile[p].resize(h+); //重新定义p堆的长度
}
//把p堆高度为h及其上方的木块整体移到p2的得尾部
void pile_onto(int p,int h,int p2)
{
for(int i=h;i<pile[p].size();i++)
pile[p2].push_back(pile[p][i]); //??
pile[p].resize(h);
}
void print()
{
for(int i=;i<n;i++)
{
printf("%d:",i);
for(int j=;j<pile[i].size();j++)
{
printf(" %d",pile[i][j]);
}
printf("\n");
}
}
int main()
{
int a,b;
scanf("%d",&n);
string s1,s2;
for(int i=;i<n;i++)
{
pile[i].push_back(i);
}
while(cin>>s1)
{
if (s1=="quit") break;
cin>>a>>s2>>b;
int pa,pb,ha,hb;
find_block(a,pa,ha);
find_block(b,pb,hb);
if(pa==pb) continue;
if(s2=="onto") clear_above(pb,hb);
if(s1=="move") clear_above(pa,ha);
pile_onto(pa,ha,pb);
}
print();
return ;
}

POJ 1208 The Blocks Problem --vector的更多相关文章

  1. POJ 1208 The Blocks Problem

    The Blocks Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5397   Accepted: 231 ...

  2. uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟

    挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: m ...

  3. B -- POJ 1208 The Blocks Problem

    参考:https://blog.csdn.net/yxz8102/article/details/53098575 https://www.cnblogs.com/tanjuntao/p/867892 ...

  4. UVa 101 The Blocks Problem Vector基本操作

    UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that inst ...

  5. uvaoj 101 - The Blocks Problem(vector应用+技巧)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=835&page= ...

  6. PKU 1208 The Blocks Problem(模拟+list应用)

    题目大意:原题链接 关键是正确理解题目意思 首先:介绍一下list容器的一些操作:参考链接 list<int> c1; c1.unique();              去重. c1.r ...

  7. The Blocks Problem(vector)

    题目链接:http://poj.org/problem?id=1208 The Blocks Problem Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  8. 【UVA - 101】The Blocks Problem(vector+模拟)

    The Blocks Problem Descriptions:(英语就不说了,直接上翻译吧) 初始时从左到右有n个木块,编号为0~n-1,要求实现下列四种操作: move a onto b: 把a和 ...

  9. UVa101 The Blocks Problem(不定长数组vector)

    The Blocks Problem 书上的一道例题,代码思路比较清晰,可以看懂. 相关知识: 若a是一个vector,则: a.size():读取它的大小 a.resize():改变大小 a.pus ...

随机推荐

  1. Swagger如何测试Date类型参数

    问题 Swagger测试时,参数直接输入日期格式化后的类型,会报参数日期转换错误 :ConversionFailedException 解决 网上说在参数上添加注解 @DateTimeFormat(p ...

  2. android实用软件tasker应用设置

    设置连接wifi和充电两个调试都满足的情况下打开同步和psiphon3:在端任意wifi是断开或断电时同步和关掉psiphon3. 其他没有问题去到关掉psiphon3时出现小意外,不能直接关闭程序( ...

  3. 用不用lambda,这是一个问题

    用不用lambda,这是一个问题  mp.weixin.qq.com Sun在2009年开启了代号为“dolphin”的工程,计划在JDK1.7中加入lambda表达式.虚拟机模块化支持.动态语言支持 ...

  4. 使用vue-cli创建vue项目

    vue-cli是官方发布的vue.js项目脚手架工具,使用它可以快速创建vue项目,github地址:https://github.com/vuejs/vue-cli 1.安装vue-cli //设置 ...

  5. null引用,有时候是实现了父类的方法,方法体没写任何实现

    null引用,有时候是实现了父类的方法,方法体没写任何实现 /* @Override public void attachView(MonthListContract.View view) { } * ...

  6. C++(2):错误:undefined reference to `__gxx_personality_v0'

    1. Linux Develop Notes     * 编译 c++ 程序需要添加 -lstdc++   sample: gcc -lstdc++ -o test test.c,否则会报 " ...

  7. Java转换流、缓冲流、流操作规律整理

    转换流 1.1                OutputStreamWriter类 OutputStreamWriter 是字符流通向字节流的桥梁:可使用指定的字符编码表,将要写入流中的字符编码成字 ...

  8. EffectiveC++ 第7章 模板与泛型编程

    我根据自己的理解,对原文的精华部分进行了提炼,并在一些难以理解的地方加上了自己的"可能比较准确"的「翻译」. Chapter 7 模版与泛型编程 Templates and Gen ...

  9. Nmpy函数总结

    函数和方法method总览 这是个Numpy函数和方法分类排列目录. 创建数组 arange, array, copy, empty, empty_like, eye, fromfile, fromf ...

  10. UE4 AR开发笔记

    1.基础使用 ArToolKit:生成图片特征,可以用彩图.(图片先灰化)    genTexData效准相机.由于有的相机照相有弧度.  calib_camera 2.使用UE4ARPlugins做 ...