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 ...
随机推荐
- ARM架构相关学习归纳总结
ARM作为一个生态不仅提供了CPU Core,还提供了一系列相关的IP,比如GIC.MMU.AMBA.CoreLink.CoreSight.Mali等等. 其他还包括Debug工具.开发工具.IDE等 ...
- 二、java三大特性--继承
在讲解之前我们先看一个例子 Husband.java public class Husband { private String name; private String sex; privatein ...
- docker[caffe&&pycaffe]
0 引言 今天花了一天,完成了整个caffe的dockerfile编写,其支持python3.6.6,这里主要的注意点是protobuf的版本(在3.6.0之后,只支持c11),还有在制作镜像的时候注 ...
- 如何应用ML的建议-下
正则化与过拟合(highvariance)和欠拟合(highbias)的关系-部分(五) ML的诊断方法-部分(六) 如何采取下一步-部分(七) 部分(五) 从图中可以看出,正则化项可以用来影响模型函 ...
- excel保存为制表符分隔的文本文件 js无法完整读取
excel保存为制表符分隔的文本文件 js无法完整读取 excel另存为文本有两个选项,一个是制表符分隔的文本文件,一个是unicode文本.生成的文件Unicode更大一些.但是这里需要注意的是[制 ...
- C#实现一张塔松叶
前段时间,Insus.NET有实现一组字符串在输出时,靠左或靠右对齐.<输出的字符靠右对齐>http://www.cnblogs.com/insus/p/7953304.html 现在In ...
- CF 799B T-shirt buying
一道超级水的练习STL的题目 题目大意:有\(n\)件T恤,每件T恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种属性.接下来有\(m\)个人每个人都有一种喜欢的颜色,他们按先后顺序 ...
- [Oracle]ORA-600[kdBlkCheckError]LOB坏块处理
[Oracle]ORA-600[kdBlkCheckError]LOB坏块处理 客户环境报如下错误: ORA - 00600: Internal error code, arguments: [kdB ...
- Asp.Net Core基于Cookie实现同域单点登录(SSO)
在同一个域名下有很多子系统 如:a.giant.com b.giant.com c.giant.com等 但是这些系统都是giant.com这个子域. 这样的情况就可以在不引用其它框架的情况下, ...
- Nagios数据存储插件NDOUtils部署和测试
1. 概述 NDOUTILS,Nagios Data Output Utils,Nagios数据输出工具,允许用户从Nagios导出状态和事件信息到数据库中,便于以后的检索和加工 它包括几个部分: N ...