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 ...
随机推荐
- Android popupMenu
popupMenu = new PopupMenu(ActivityHousesNumList.this, imageViewhousesnum1); popupMenu.getMenuInflate ...
- 计算机网络协议OSI TCP/IP协议--001
网桥:连接同构的LAN的网络互联设备,(同构的LAN 网是,应用层到逻辑层) 实 现的功能是:MAC子层和物理层.1.帧的发送与接收.2.缓冲的管理.3.协议转换. 路由器:在网络层实现互联,他 ...
- WPF中DataGrid中的DataGridCheckBoxColumn用法(全选,全否,反选)
原文:WPF中DataGrid中的DataGridCheckBoxColumn用法(全选,全否,反选) 前台代码 <DataGrid.Columns> <DataGridCheckB ...
- 【转】分布式一致性算法:Raft 算法(Raft 论文翻译)
编者按:这篇文章来自简书的一个位博主Jeffbond,读了好几遍,翻译的质量比较高,原文链接:分布式一致性算法:Raft 算法(Raft 论文翻译),版权一切归原译者. 同时,第6部分的集群成员变更读 ...
- Jquery 图片延迟加载技术
参考网址:http://code.ciaoca.com/jquery/lazyload/ 延迟加载能大大增加你网站的加载速度! 需要引入以下文件<Jq文件也是少不了的>: <scri ...
- openhtmltopdf 支持自定义字体、粗体
一.支持自定义字体 private static void renderPDF(String html, OutputStream outputStream) throws Exception { t ...
- Tomcat利用MSM实现Session共享方案解说
Session共享有多种解决方法,常用的有四种:1)客户端Cookie保存2)服务器间Session同步3)使用集群管理Session(如MSM) 4)把Session持久化到数据库 针对上面Sess ...
- LVS+Keepalived 高可用环境部署记录(主主和主从模式)
之前的文章介绍了LVS负载均衡-基础知识梳理, 下面记录下LVS+Keepalived高可用环境部署梳理(主主和主从模式)的操作流程: 一.LVS+Keepalived主从热备的高可用环境部署 1)环 ...
- SE Springer小组之《Spring音乐播放器》需求分析说明书二
2.1 目标 Spring音乐播放器软件为课程<软件工程>所开发的课程作业,主要意图是为访问计算机中的mp3格式的音频文件,并使其能够完成访问,读取,添加,保存,播放,切换音频文件等功能. ...
- Aop事务小结(事务管理器和自身构建)
声明市事务是利用AOP来实现的. 1.采用事务管理器AOP: <!--3.配置事务切面:控制住连接池 --> <bean id="transactionManager&qu ...