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 ...
随机推荐
- bzoj 4260: Codechef REBXOR (01 Trie)
链接: https://www.lydsy.com/JudgeOnline/problem.php?id=4260 题面: 4260: Codechef REBXOR Time Limit: 10 S ...
- STM32的IO口是如何配置为某个外设使用的 ---?
@2019-03-01 [猜想] 使用片内外设功能: 首先将对应 IO 口配置为复用输出 其次是 IO 口对应的多个功能外设,哪个外设使能即将外设与 IO 口相连 [疑问] 若多个外设都使能,那么到底 ...
- Mock7 moco框架重定向
新建一个startupWithRedirect.json [ { "description": "重定向到百度", "request": { ...
- Linux设备树(四 中断)
四 中断 中断一般包括中断产生设备和中断处理设备.中断控制器负责处理中断,每一个中断都有对应的中断号及触发条件.中断产生设备可能有多个中断源,有时多个中断源对应中断控制器中的一个中断,这种情况中断产生 ...
- Node.js模块化教程
Node.js模块化教程 下载安装node.js 创建项目结构 |-modules |-module1.js |-module2.js |-module3.js|-app.js|-package.js ...
- Python常用模块-时间模块
在写代码的过程中,我们常常需要与时间打交道,在python中,与时间处理有关的模块有time,datetime和calendar.,这里主要介绍time和datetime模块 在python中,表示时 ...
- 高并发秒杀系统--Service事务管理与继承测试
[Spring IoC的类型及应用场景] [Spring事务使用方式] [Spring事务的特性] [Spring事务回滚的理解] [Service声明式事务的配置] 1.配置事务管理器 2.配置基 ...
- 鼠标右键添加Sublime Text
鼠标右键添加Sublime Text 参考 将sublime添加到鼠标右键 实践 1. win+R 输入regedit 2. 输入路径: 计算机\HKEY_CLASSES_ROOT\*\shell\ ...
- pythonのdjango CSRF简单使用
一.简介 django为用户实现防止跨站请求伪造的功能,通过中间件 django.middleware.csrf.CsrfViewMiddleware 来完成.而对于django中设置防跨站请求伪造功 ...
- Spring Cloud 2-Feign 声明式服务调用(三)
Spring Cloud Feign 1. pom.xml 2. application.yml 3. Application.java 4. Client.java 简化RestTemplate调 ...