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 ...
随机推荐
- LoadRunner开发ftp协议接口之上传文件脚本
Action() { //建立一个ftp对象 FTP ftp1=0; //建立FTP连接并登录 ftp_logon_ex(&ftp1,"ftpLogon", "U ...
- pta寒假作业3
题目三:捉老鼠啊,亏了还是赚了 实验代码 #include <stdio.h> #include <stdlib.h> int main(void) { ...
- 微信小程序之动态添加、删除指定内容(view)和获取input值
这次遇到个问题: 1. 动态的添加指定的view内容..嗯..很简单..wx:for就搞定 2. 动态添加的内容中有input,最终获取值的时候,要获取到所有input的值并且是一个数组..嗯.. 3 ...
- mysql数据库truncate表时间长处理
[环境介绍] 系统环境:Linux + mysql 5.7.18 + 主从复制架构 [背景描述] 客户反映用在mysql数据库上truncate一个innode引擎的list分区100G左右表时,耗时 ...
- C# 插件化方案(Add-In)
白话插件框架原理 WPF 插件开发(.NET Framework 3.5 System.Addin) 原文:AddIn Enabled Applications
- QMainWindow-状态栏
self.status_bar = self.statusBar() # 显示状态栏 self.setStatusTip('这是一个窗口') #鼠标在指定控件上时,状态栏 ...
- JAVA进阶12
间歇性混吃等死,持续性踌躇满志系列-------------第12天 1.字符串的概述和特点 java.lang.String类代表字符串 API当中说,Java程序中所有的字符串字面值(如“abc& ...
- WPS或xls 数据分列 清洗
一 .一般分离 时间:2017年11月27日14:55:12 数据如下: 501陈**:田莨铺58 502陈**:田莨铺58 503陈**.六麻杨冲58元 504陈**.石脚哗.200元 505陈** ...
- setTimeout 第三个参数秒懂
好吧,假设你们都是从 ES6 里 promise 发现 setTimeout 还有第三个参数的,下面讲讲到底是干嘛的 setTimeout 第三个及之后的参数作用:定时器启动时候,第三个以后的参数是作 ...
- keepalive半同步双主一从
ip地址如下: 192.168.20.201 redis01 主 192.168.20.202 redis02 主 192.168.20.203 redis03 从 192.168.20.205 vi ...