一道有点复杂的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. SQL Server 索引中include的魅力(具有包含性列的索引)(转载)

    开文之前首先要讲讲几个概念 [覆盖查询] 当索引包含查询引用的所有列时,它通常称为“覆盖查询”.  [索引覆盖] 如果返回的数据列就包含于索引的键值中,或者包含于索引的键值+聚集索引的键值中,那么就不 ...

  2. 简单的策略模式Strategy演示

    策略模式,即规则在变化之中,结果终归为一. 公司给员工计算工资,如有加班费,差旅费,每个月的生活补帖等等其它费用需要计算.这个费的规则是不尽相同. 不管策略的规则怎样,终归需要计算出一个结果 工资: ...

  3. 马加爵遗书 VS 药家鑫遗书

          前言:今天是贰零壹柒年最后一个工作日,亦是2017年12月29日,因为明天就放元旦假了,公司同事比往常相对轻松些.中午吃完午饭,在办公室大家有说有笑,有人说姓马的人都挺牛X啊,比如:马云, ...

  4. [Spark][Hive]Hive的命令行客户端启动:

    [Spark][Hive]Hive的命令行客户端启动: [training@localhost Desktop]$ chkconfig | grep hive hive-metastore 0:off ...

  5. GBDT和随机森林的区别

    GBDT和随机森林的相同点: 1.都是由多棵树组成 2.最终的结果都是由多棵树一起决定 GBDT和随机森林的不同点: 1.组成随机森林的树可以是分类树,也可以是回归树:而GBDT只由回归树组成 2.组 ...

  6. CRC---循环冗余校验

    typedef unsigned char uchar; typedef unsigned int uint; typedef unsigned short uInt16; uint crc; // ...

  7. 11.10 (下午)开课二个月零六天(ajax验证用户名,ajax调数据库)

    用ajax验证用户名是否可用 testuid.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...

  8. 在Windows7上如何找到Cookie

    摘要 出于兴趣爱好,前一阵子做了一个网页,网页中需要用到Cookie,但是,根据书上的说明,并没有找打教材中所说的Cookie的位置,本文就主要介绍在计算机(Win7)中Cookie的存放位置,同样适 ...

  9. ElasticSearch实践系列(三):探索数据

    前言 经过前两篇文章得实践,我们已经了解了ElasticSearch的基础知识,本篇文章让我来操作一些更真实的数据集.我们可以利用www.json-generator.com/生成如下的文档结构: { ...

  10. 【IDEA】Intellij IDEA创建的Web项目配置Tomcat并启动Maven项目

    转载请注明出处:http://blog.csdn.net/qq_26525215本文源自[大学之旅_谙忆的博客] 本篇博客讲解IDEA如何配置Tomcat. 大部分是直接上图哦. 点击如图所示的地方, ...