POJ 1208 The Blocks Problem --vector
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的更多相关文章
- POJ 1208 The Blocks Problem
The Blocks Problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5397 Accepted: 231 ...
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: m ...
- B -- POJ 1208 The Blocks Problem
参考:https://blog.csdn.net/yxz8102/article/details/53098575 https://www.cnblogs.com/tanjuntao/p/867892 ...
- UVa 101 The Blocks Problem Vector基本操作
UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that inst ...
- uvaoj 101 - The Blocks Problem(vector应用+技巧)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=835&page= ...
- PKU 1208 The Blocks Problem(模拟+list应用)
题目大意:原题链接 关键是正确理解题目意思 首先:介绍一下list容器的一些操作:参考链接 list<int> c1; c1.unique(); 去重. c1.r ...
- The Blocks Problem(vector)
题目链接:http://poj.org/problem?id=1208 The Blocks Problem Time Limit: 1000MS Memory Limit: 10000K Tot ...
- 【UVA - 101】The Blocks Problem(vector+模拟)
The Blocks Problem Descriptions:(英语就不说了,直接上翻译吧) 初始时从左到右有n个木块,编号为0~n-1,要求实现下列四种操作: move a onto b: 把a和 ...
- UVa101 The Blocks Problem(不定长数组vector)
The Blocks Problem 书上的一道例题,代码思路比较清晰,可以看懂. 相关知识: 若a是一个vector,则: a.size():读取它的大小 a.resize():改变大小 a.pus ...
随机推荐
- radio,check美化
单选框与复选框原生控件美化有多种解决方案,现在采用经典的input+label的方式自己实现一种 思路: input 和label 通过id和for属性关联,点击label时,input选中状态改变 ...
- (最短路 Floyd) P2910 [USACO08OPEN]寻宝之路Clear And Present Danger 洛谷
题意翻译 题目描述 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛. 一张藏宝图上说,如果他的路程上经过的小岛依次出现了 ...
- mac开发环境搭建篇(2)--brew与mysql
[brew]:参考 https://www.cnblogs.com/zoulifeng2017/p/7514139.html 安装brew: 终端执行:/usr/bin/ruby -e "$ ...
- 2017-12-19python全栈9期第四天第二节之列表的增删查改之公共方法len和count和index
#!/user/bin/python# -*- coding:utf-8 -*-li = ['zs','ls','ww','zl','xx']l = len(li) #总数print(l)num = ...
- busybox(二)编译
title: busybox(二)编译 tag: arm date: 2018-11-13 23:14:58 --- busybox(二)编译 解压,源码包在busybox-1.7.0.tar.bz2 ...
- Linux中的pipe(管道)与named pipe(FIFO 命名管道)
catalogue . pipe匿名管道 . named pipe(FIFO)有名管道 1. pipe匿名管道 管道是Linux中很重要的一种通信方式,是把一个程序的输出直接连接到另一个程序的输入,常 ...
- 如何给pdf文件中的一页添加水印
如题所述,项目需求.要把一份文件尾部加上签章,首先想到的就是水印. 开始试过了无论是word还是wps所谓的水印其实就是页脚或页眉统一格式,无法单一一个页面操作,要加所有的页面都有. 纵然wps有个功 ...
- 源码来袭:call、apply手写实现与应用
关于this指向可以了解我的另一篇博客:JavaScript中的this指向规则. 一.call与apply的使用 回顾call与apply的this指向: var value = "win ...
- 关于使用python ~取反操作符带出的一系列问题
晚上的时候,无意之间看到stackoverflow上面的一个编程挑战赛,各路高手各种搞事,看到python的地方突然发现用了很多位运算的符号,但是~符号引起了我和同事的注意. 我们很少在程序中使用这种 ...
- About the Importance of Aim in Life
Have an aim in life, or your energies will all be wasted. ---R. Peters 人生应该树立目标,否则你的精力会白白浪费. ---彼得 ...