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 ...
随机推荐
- P1962 斐波那契数列
题面是这样的,其实斐波那契我们之前也有接触过,并不是什么太陌生的玩意,第一个想到的方法其实是用递归来做,这样的话其实是非常轻松的,but同志们你们有没有关注过这样一个鬼东西 你以为蓝题是让你切着玩的吗 ...
- vue实战记录(六)- vue实现购物车功能之地址列表选配
vue实战,一步步实现vue购物车功能的过程记录,课程与素材来自慕课网,自己搭建了express本地服务器来请求数据 作者:狐狸家的鱼 本文链接:vue实战-实现购物车功能(六) GitHub:sue ...
- [SHOI2008]仙人掌图 II——树形dp与环形处理
题意: 给定一个仙人掌,边权为1 距离定义为两个点之间的最短路径 直径定义为距离最远的两个点的距离 求仙人掌直径 题解: 类比树形dp求直径. f[i]表示i向下最多多长 处理链的话,直接dp即可. ...
- 2018年秋季学期《c语言程序设计》学习总结
<c语言程序设计>第四周学习总结 <c语言程序设计>第五周学习总结 <c语言程序设计>第六周学习总结 <c语言程序设计>第七周学习总结 <c语言程 ...
- Kubenetes 资源清单定义入门
Kubernetes 常用资源 资源 对象 工作负载型资源对象(workload): Pod Replicaset ReplicationController Deployments Stat ...
- Linux下 tftp 服务器的安装与使用
安装步骤: 1. 安装xinetd, tftp-hpa tftpd-hpa a. sudo apt-get install xinetd b. sudo apt-get install tftp- ...
- 深入理解 LINQ to SQL 生成的 SQL 语句
Ø 简介 在 C# 中与数据交互最常用的语句就是 LINQ 了,而 LINQ to SQL 是最直接与数据库打交道的语句,它可以根据 LINQ 语法生成对应的 SQL 语句,在数据库中去执行.本文主 ...
- Spring MVC 使用问题与解决--HTTP Status 500 - Servlet.init() for servlet springmvc threw exception
1.HTTP Status 500 - Servlet.init() for servlet springmvc threw exception 解决 使用jre1.7 Spring4.3 2.spr ...
- Coursera, Big Data 3, Integration and Processing (week 1/2/3)
This is the 3rd course in big data specification courses. Data model reivew 1, data model 的特点: Struc ...
- 基于STM32F1的时钟芯片DS1302驱动
目录 DS1302.h源代码 DS1302.c源代码 DS1302.h源代码 /** ********************************************************* ...