Uva101-STL模拟
一道有点复杂的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模拟的更多相关文章
- stl+模拟 CCF2016 4 路径解析
// stl+模拟 CCF2016 4 路径解析 // 一开始题意理解错了.... #include <iostream> #include <string> #include ...
- 【STL+模拟】UVa 506 - System Dependencies
System Dependencies Components of computer systems often have dependencies--other components that m ...
- STL——模拟实现空间配置器
目录 问题 SGI版本空间配置器-std::alloc 一级空间配置器 二级空间配置器 Refill.chunkAlloc函数 最后,配置器封装的simple_alloc接口 问题 我们在日常编写C+ ...
- 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. ...
- CCF 201403-3 命令行选项 (STL模拟)
问题描述 请你写一个命令行分析程序,用以分析给定的命 令行里包含哪些选项.每个命令行由若干个字符串组成,它们之间恰好由一个空格分隔.这些字符串中的第一个为该命令行工具的名字,由小写字母组成,你的程序 ...
- CCF 201403-2 窗口 (STL模拟)
问题描述 在某图形操作系统中,有 N 个窗口,每个窗口都是一个两边与坐标轴分别平行的矩形区域.窗口的边界上的点也属于该窗口.窗口之间有层次的区别,在多于一个窗口重叠的区域里,只会显示位于顶层的窗口里的 ...
- uva 327 Evaluating Simple C Expressions 简易C表达式计算 stl模拟
由于没有括号,只有+,-,++,--,优先级简单,所以处理起来很简单. 题目要求计算表达式的值以及涉及到的变量的值. 我这题使用stl的string进行实现,随便进行练手,用string的erase删 ...
- HDU5071 - Chat(STL模拟)
题目描述 略... 题解 现场赛的时候真是脑残...用splay去写..写完发现调试不出来...然后才发现数据范围才5000...不过那时候只有40分钟了..用数组模拟了速度敲了一发.写完只剩10几分 ...
- 牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A
牛客练习赛31 D 神器大师泰兹瑞与威穆 https://ac.nowcoder.com/acm/contest/218/D 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26214 ...
- 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 ...
随机推荐
- Redis 安装部署
1. 官网(https://redis.io/download)下载稳定版安装包 3.0.7或3.2或4.1; 2. 复制到部署服务器 /opt/redis4,解压 tar zxvf redis-4. ...
- 1-微信小程序开发(安装软件和运行第一个微信小程序)
https://developers.weixin.qq.com/miniprogram/dev/ 我的 打开 上传成功后
- 通过jQuery Ajax使用FormData对象上传文件 (转载)
XMLHttpRequest Level 2 添加了一个新的接口——FormData.与普通的 Ajax 相比,使用 FormData 的最大优点就是我们可以异步上传二进制文件.jQuery 2.0+ ...
- SQL Server中删除用户时报错,提示:The database principal owns a schema in the database, and cannot be dropped(转载)
Description of the problem: When you tried to drop a user, you got this message: Error: 15138 The da ...
- ( 转)Ubuntu下创建、重命名、删除文件及文件夹,强制清空回收站方法
Ubuntu下创建.重命名.删除文件及文件夹,强制清空回收站方法 mkdir 目录名 ——创建一个目录 rmdir 空目录名 ——删除一个空目录 rm 文件名 文件名 ——删除一个文件或多个文件 rm ...
- C#基础巩固(2)-Linq To XML创建XML
一.首先要清楚一个正确的XML基本格式是怎样的. 1.后缀名.xml结尾 2.有一行描述 3.有且仅有一个根节点. 如图: 一个正确的xml文件能够被浏览器打开且显示.所以判断一个xml文件有没有错误 ...
- Jlink使用技巧之合并烧写文件
前言 IAP(In-application-programming),即在应用中编程.当产品发布之后,可以通过网络方便的升级固件程序,而不需要拆机下载程序.IAP系统的固件一般由两部分组成,即Boot ...
- [HAOI2017]方案数[组合计数、容斥、dp]
题意 题目链接 分析 先考虑没有障碍怎么做,定义 f(i,j,k) 每一维走了 i,j,k 位的方案数,转移乘个组合数即可. 现在多了一些障碍,考虑容斥.实际我们走过的点都有严格的大小关系,所以先把所 ...
- 机器学习 第五篇:分类(kNN)
K最近邻(kNN,k-NearestNeighbor)算法是一种监督式的分类方法,但是,它并不存在单独的训练过程,在分类方法中属于惰性学习法,也就是说,当给定一个训练数据集时,惰性学习法简单地存储或稍 ...
- flask-admin 快速打造博客 系列一
前言: 我想分享flask+flask-admin快速打造博客的详细教程,可是发现网易课堂已经有相应的免费课堂了,所以就不打算一点一滴的在这里做笔记,分享这些东西了.所以我主要集中在flask-adm ...