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

晚点仔细看

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

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. #include<iostream>
  5. #include<stdlib.h>
  6. #include<algorithm>
  7. #include<queue>
  8. #include<vector>
  9. #include<string>
  10. #define mem(a) memset(a,0,sizeof(a))
  11. using namespace std;
  12. const long long N=1e9+;
  13. #define LL long long
  14. vector<int> pile[];
  15. int n;
  16.  
  17. //查找木块a所在的pile和height
  18. void find_block(int a,int &p,int &h) //引用,相当于直接用实参
  19. {
  20. for(p=;p<n;p++)
  21. {
  22. for(h=;h<pile[p].size();h++)
  23. {
  24. if(pile[p][h]==a) return;
  25. //vector就像一个二维数组,只是第一维大小固定(30),二维大小不固定。
  26. }
  27. }
  28. }
  29. //把p堆高度为h的木块上方所有的木块移回原位置
  30. void clear_above(int p,int h)
  31. {
  32. for(int i=h+;i<pile[p].size();i++)
  33. {
  34. int t=pile[p][i];
  35. pile[t].push_back(t); ////把标号为t的木块放回原位,即t堆
  36. }
  37. pile[p].resize(h+); //重新定义p堆的长度
  38. }
  39. //把p堆高度为h及其上方的木块整体移到p2的得尾部
  40. void pile_onto(int p,int h,int p2)
  41. {
  42. for(int i=h;i<pile[p].size();i++)
  43. pile[p2].push_back(pile[p][i]); //??
  44. pile[p].resize(h);
  45. }
  46. void print()
  47. {
  48. for(int i=;i<n;i++)
  49. {
  50. printf("%d:",i);
  51. for(int j=;j<pile[i].size();j++)
  52. {
  53. printf(" %d",pile[i][j]);
  54. }
  55. printf("\n");
  56. }
  57. }
  58. int main()
  59. {
  60. int a,b;
  61. scanf("%d",&n);
  62. string s1,s2;
  63. for(int i=;i<n;i++)
  64. {
  65. pile[i].push_back(i);
  66. }
  67. while(cin>>s1)
  68. {
  69. if (s1=="quit") break;
  70. cin>>a>>s2>>b;
  71. int pa,pb,ha,hb;
  72. find_block(a,pa,ha);
  73. find_block(b,pb,hb);
  74. if(pa==pb) continue;
  75. if(s2=="onto") clear_above(pb,hb);
  76. if(s1=="move") clear_above(pa,ha);
  77. pile_onto(pa,ha,pb);
  78. }
  79. print();
  80. return ;
  81. }

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. bzoj 4260: Codechef REBXOR (01 Trie)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=4260 题面: 4260: Codechef REBXOR Time Limit: 10 S ...

  2. STM32的IO口是如何配置为某个外设使用的 ---?

    @2019-03-01 [猜想] 使用片内外设功能: 首先将对应 IO 口配置为复用输出 其次是 IO 口对应的多个功能外设,哪个外设使能即将外设与 IO 口相连 [疑问] 若多个外设都使能,那么到底 ...

  3. Mock7 moco框架重定向

    新建一个startupWithRedirect.json [ { "description": "重定向到百度", "request": { ...

  4. Linux设备树(四 中断)

    四 中断 中断一般包括中断产生设备和中断处理设备.中断控制器负责处理中断,每一个中断都有对应的中断号及触发条件.中断产生设备可能有多个中断源,有时多个中断源对应中断控制器中的一个中断,这种情况中断产生 ...

  5. Node.js模块化教程

    Node.js模块化教程 下载安装node.js 创建项目结构 |-modules |-module1.js |-module2.js |-module3.js|-app.js|-package.js ...

  6. Python常用模块-时间模块

    在写代码的过程中,我们常常需要与时间打交道,在python中,与时间处理有关的模块有time,datetime和calendar.,这里主要介绍time和datetime模块 在python中,表示时 ...

  7. 高并发秒杀系统--Service事务管理与继承测试

    [Spring IoC的类型及应用场景]  [Spring事务使用方式] [Spring事务的特性] [Spring事务回滚的理解] [Service声明式事务的配置] 1.配置事务管理器 2.配置基 ...

  8. 鼠标右键添加Sublime Text

    鼠标右键添加Sublime Text 参考 将sublime添加到鼠标右键 实践 1. win+R 输入regedit 2. 输入路径: 计算机\HKEY_CLASSES_ROOT\*\shell\ ...

  9. pythonのdjango CSRF简单使用

    一.简介 django为用户实现防止跨站请求伪造的功能,通过中间件 django.middleware.csrf.CsrfViewMiddleware 来完成.而对于django中设置防跨站请求伪造功 ...

  10. Spring Cloud 2-Feign 声明式服务调用(三)

    Spring Cloud Feign  1. pom.xml 2. application.yml 3. Application.java 4. Client.java 简化RestTemplate调 ...