一道有点复杂的STL模拟题,对STL迭代器不太熟悉改了好久,最后总算A了出来。

感觉用数组更方便。。。但是为了练习STL嘛

对比白书上的代码,我写的还是傻了点。一开始没有理解四个操作的意思,单纯的模拟。

#include <algorithm>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> using namespace std; int N,M,T;
vector <int> v[]; int getpos(int x)
{
for(int i=;i<N;i++)
{
vector <int>::iterator it = v[i].begin();
it = find(v[i].begin(),v[i].end(),x);
if(it != v[i].end())
{
return i;
}
}
return -;
} void repose(int x,int a)
{
for(vector<int>::iterator it = v[x].begin();it != v[x].end();++it)
{
if(*it == a)
{
if(++it == v[x].end()) return;
for(vector<int>::iterator it2 = it;it2 != v[x].end();++it2)
{
int k = *it2;
vector<int>::iterator beg = v[k].begin();
//printf("%d %d\n",k,(int)v[k].size());
//- while(1);
v[k].insert(beg,k);
}
v[x].erase(it,v[x].end());
break;
}
}
return;
} void move_onto(int a,int b)
{
int x = getpos(a),y = getpos(b);
repose(x,a);repose(y,b);
for(vector<int>::iterator it = v[x].begin();it != v[x].end();++it)
{
if(*it == a)
{
v[x].erase(it);
break;
}
}
for(vector<int>::iterator it = v[y].begin();it != v[y].end();++it)
{
if(*it == b)
{
v[y].push_back(a);
break;
}
}
return;
} void move_over(int a,int b)
{
int x = getpos(a),y = getpos(b);
repose(x,a);
for(vector<int>::iterator it = v[x].begin();it != v[x].end();++it)
{
if(*it == a)
{
v[x].erase(it);
break;
}
}
v[y].push_back(a);
return;
} void pile_over(int a,int b)
{
int x = getpos(a),y = getpos(b);
for(vector<int>::iterator it = v[x].begin();it != v[x].end();++it)
{
if(*it == a)
{
for(vector<int>::iterator it2 = it;it2 != v[x].end();++it2) v[y].push_back(*it2);
v[x].erase(it,v[x].end());
break;
}
}
return;
} void pile_onto(int a,int b)
{
int x = getpos(a),y = getpos(b);
repose(y,b);
for(vector<int>::iterator it = v[x].begin();it != v[x].end();++it)
{
if(*it == a)
{
for(vector<int>::iterator it2 = it;it2 != v[x].end();++it2) v[y].push_back(*it2);
v[x].erase(it,v[x].end());
break;
}
}
return;
} int main()
{
while(~scanf("%d",&N))
{
int a,b;
char op[],s[];
for(int i=;i<N;i++) {v[i].clear();v[i].push_back(i);} while(scanf("%s",op) && op[] != 'q')
{
scanf("%d %s %d",&a,s,&b);
if(getpos(a) == getpos(b)) continue;
if(!strcmp(op,"move") && !strcmp(s,"onto")) move_onto(a,b);
else if(!strcmp(op,"move") && !strcmp(s,"over")) move_over(a,b);
else if(!strcmp(op,"pile") && !strcmp(s,"onto")) pile_onto(a,b);
else if(!strcmp(op,"pile") && !strcmp(s,"over")) pile_over(a,b);
}
for(int i=;i<N;i++)
{
printf("%d:",i);
for(int j = ;j < (int)v[i].size();j++) printf(" %d",v[i][j]);
printf("\n");
}
}
}

Uva101-STL模拟的更多相关文章

  1. stl+模拟 CCF2016 4 路径解析

    // stl+模拟 CCF2016 4 路径解析 // 一开始题意理解错了.... #include <iostream> #include <string> #include ...

  2. 【STL+模拟】UVa 506 - System Dependencies

    System Dependencies  Components of computer systems often have dependencies--other components that m ...

  3. STL——模拟实现空间配置器

    目录 问题 SGI版本空间配置器-std::alloc 一级空间配置器 二级空间配置器 Refill.chunkAlloc函数 最后,配置器封装的simple_alloc接口 问题 我们在日常编写C+ ...

  4. UVA - 11995 - I Can Guess the Data Structure! STL 模拟

    There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...

  5. CCF 201403-3 命令行选项 (STL模拟)

    问题描述 请你写一个命令行分析程序,用以分析给定的命 令行里包含哪些选项.每个命令行由若干个字符串组成,它们之间恰好由一个空格分隔.这些字符串中的第一个为该命令行工具的名字,由小写字母组成,你的程序 ...

  6. CCF 201403-2 窗口 (STL模拟)

    问题描述 在某图形操作系统中,有 N 个窗口,每个窗口都是一个两边与坐标轴分别平行的矩形区域.窗口的边界上的点也属于该窗口.窗口之间有层次的区别,在多于一个窗口重叠的区域里,只会显示位于顶层的窗口里的 ...

  7. uva 327 Evaluating Simple C Expressions 简易C表达式计算 stl模拟

    由于没有括号,只有+,-,++,--,优先级简单,所以处理起来很简单. 题目要求计算表达式的值以及涉及到的变量的值. 我这题使用stl的string进行实现,随便进行练手,用string的erase删 ...

  8. HDU5071 - Chat(STL模拟)

    题目描述 略... 题解 现场赛的时候真是脑残...用splay去写..写完发现调试不出来...然后才发现数据范围才5000...不过那时候只有40分钟了..用数组模拟了速度敲了一发.写完只剩10几分 ...

  9. 牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A

    牛客练习赛31 D 神器大师泰兹瑞与威穆 https://ac.nowcoder.com/acm/contest/218/D 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26214 ...

  10. Educational Codeforces Round 24 A 水 B stl C 暴力 D stl模拟 E 二分

    A. Diplomas and Certificates time limit per test 1 second memory limit per test 256 megabytes input ...

随机推荐

  1. Linux 局域网同步时间

    选择一台能上外网的机器作为时间服务器(都不能上亦可以,任选一台即可,但是只能保证局域网内时间同步) 配置此时间服务器 安装 ntp 在 /etc/ntp.conf 中配置 restrict 127.0 ...

  2. linux 修改内核参数 如何生效?

    Linux 操作系统修改内核参数有3种方式: 修改 /etc/sysctl.conf 文件,加入配置选项,格式为 key = value ,修改保存后调用 sysctl -p 加载新配置使用 sysc ...

  3. CF11D A Simple Task 状压DP

    传送门 \(N \leq 19\)-- 不难想到一个状压:设\(f_{i,j,k}\)表示开头为\(i\).结尾为\(j\).经过的点数二进制下为\(k\)的简单路总数,贡献答案就看\(i,j\)之间 ...

  4. HihoCoder1192 简单的树嵌入 dfs、构造

    题目传送门:http://hihocoder.com/problemset/problem/1192 大意:给出一棵$N$个点的树,边权为$1$,要求给每个点构造$M$个权值$v_1...v_M$,使 ...

  5. Vue-认识状态管理vuex

    vuex是一个专门为vue.js设计的状态管理模式,并且也可以使用devtools进行调试,可以多个组件共享状态.简单来说,就是共享的状态用state来存放,用mutations来操作state,但是 ...

  6. 在angularjs实现一个时钟

    想在网页上,显示当前系统时钟. <body ng-app="App2" ng-controller="Ctrl2"> <div ng-bind ...

  7. [Oracle]PDB Clone 方法

    Source: SQL> alter pluggable databse pdb1 open; Target: SQL> alter session set container=cdb$r ...

  8. python 小问题收集

    1,python安装sqlclient yum install python36u python36u-devel yum install gcc mariadb-devel pip3 install ...

  9. M1m2分析报告

    个人博客链接: http://www.cnblogs.com/kjzxzzh/p/4074386.html http://www.cnblogs.com/kjzxzzh/p/4027699.html ...

  10. 关于在VB.NET中调用使用VC++编写的类库dll的一点笔记

    前言 结对作业要求一出来,我就立刻想到了把“计算核心”封装成dll,然后使用vb.net编写UI调用dll的思路.然而在实现过程中却遇到了很多的问题. 我在这个过程中是负责使用vb.net编写UI并调 ...