先看UVA11995

两份代码一份直接用C写的,一份用STL写的

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
//#include <priority_queue>
using namespace std;
int a[1005];
int b[1005];
int c[1005];
struct ope
{
int x;
int y;
}op[1005];
int v[4];//1队列 2栈 3优先队列
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
memset(v,0,sizeof(v));
int cnt1=0,cnt2=0,cnt3=0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&op[i].x,&op[i].y);
}
for(int i=0;i<n;i++)
{
if(op[i].x==1)
{
a[cnt1++]=op[i].y;
}
if(op[i].x==2)
{
if(cnt1-1<0) { v[1]=1;}
else
{
int temp=0;
for(int jj=0;jj<cnt1;jj++)
{
if(a[jj]==0){temp++; continue ;}
else
{
if(a[jj]==op[i].y)
{
a[jj]=0;
break;
}
else {v[1]=1;break;}
}
}
if(temp==cnt1) v[1]=1;
}
}
if(op[i].x==1)
{
b[cnt2++]=op[i].y;
}
if(op[i].x==2)
{
int temp=0;
if(cnt2-1<0) {v[2]=1;}
else
{
for(int jj=cnt2-1;jj>=0;jj--)
{
if(b[jj]==0) {temp++;continue;}
else
{
if(b[jj]==op[i].y)
{b[jj]=0;break;}
else v[2]=1;break; }
}
if(temp==cnt2) {v[2]=1;} }
}
if(op[i].x==1)
{
c[cnt3++]=op[i].y;
}
if(op[i].x==2)
{
if(cnt3-1<0) v[3]=1;
else
{
int temp3,max=-1;
for(int jj=0;jj<cnt3;jj++)
if(c[jj]>max){temp3=jj; max=c[jj];}
if(max==op[i].y) c[temp3]=0;
else v[3]=1;
}
} }
if(!v[1]&&v[2]==1&&v[3]==1)
printf("queue\n");
else if(v[1]==1&&!v[2]&&v[3]==1)
printf("stack\n");
else if(v[1]==1&&v[2]==1&&!v[3])
printf("priority queue\n");
else if(v[1]==1&&v[2]==1&&v[3]==1)
printf("impossible\n");
else printf("not sure\n");
}
return 0;
} STL版~ #include<cstdio>
#include<stack>
#include<queue>
using namespace std;
const int maxn = 1000+100;
int id[maxn],x[maxn],n;
bool isStack(){
stack<int> s;
for(int i=0;i<n;i++){
if(id[i]==1) s.push(x[i]);
else{
if(s.empty()) return false;
int val=s.top(); s.pop();
if(x[i]!=val) return false;
}
}
return true;
}
bool isQueue(){
queue<int >q;
for(int i=0;i<n;i++){
if(id[i]==1) q.push(x[i]);
else{
if(q.empty()) return false;
int val=q.front(); q.pop();
if(x[i]!=val) return false;
}
}
return true; }
bool isPriority(){
priority_queue<int > q;
for(int i=0;i<n;i++){
if(id[i]==1) q.push(x[i]);
else{
if(q.empty()) return false;
int val=q.top(); q.pop();
if(x[i]!=val) return false;
}
}
return true;
}
int main(){
while(scanf("%d",&n)!=EOF){
bool st=false,qu=false,pr=false;
for(int i=0;i<n;i++){
scanf("%d %d",&id[i],&x[i]);
}
st=isStack(); qu=isQueue(); pr=isPriority();
if(!st&&!qu&&!pr) puts("impossible");
else if((!st&&qu&&pr)||(!qu&&st&&pr)||(!pr&&qu&&st)||pr&&qu&&st){
puts("not sure");
}
else if(st) puts("stack");
else if(qu) puts("queue");
else if(pr) puts("priority queue"); }
return 0;
}

queue,stack,priority_queue取顶部or底部元素,front,top,back,push,pop.......

接下来是UVA11991

附代码

#include<iostream>
#include<vector>
#include<map>
#include<stdio.h>
using namespace std;
map<int,vector<int> > a;
int main()
{
int n,m,x,y;
while(scanf("%d%d",&n,&m)==2)
{
a.clear();
for(int i=0;i<n;i++)
{
scanf("%d",&x);
if(!a.count(x))
a[x]=vector<int>();
a[x].push_back(i+1);
}
while(m--)
{
scanf("%d%d",&x,&y);
if(!a.count(y)||a[y].size()<x)
printf("0\n");
else printf("%d\n",a[y][x-1]);
}
}
return 0;
}

map,vector用法。。

map里面的count用法。。

UVA11995【I can guess the data structrue!!】【水】+UVA11991【map用法】的更多相关文章

  1. 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!

    UVa11995  I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...

  2. uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)

    11995 - I Can Guess the Data Structure! There is a bag-like data structure, supporting two operation ...

  3. UVA11995 I Can Guess the Data Structure!

    思路 简单题,用栈,队列,优先队列直接模拟即可 代码 #include <cstdio> #include <algorithm> #include <cstring&g ...

  4. Css中路径data:image/png;base64的用法详解

    今天查看一些网站的css中发现了 background-image:url(data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAEAAAAkCAYAAAB ...

  5. Css中路径data:image/png;base64的用法详解 (转载)

    大家可能注意到了,网页上有些图片的src或css背景图片的url后面跟了一大串字符,比如: background-image:url(data:image/png;base64, iVBORw0KGg ...

  6. mysql中使用load data infile导入数据的用法

    有时需要将大量数据批量写入数据库,直接使用程序语言和Sql写入往往很耗时间,其中有一种方案就是使用mysql load data infile导入文件的形式导入数据,这样可大大缩短数据导入时间. LO ...

  7. $.each(data, function (index, value) { })的用法;json和list<>的互相转换

    在json中常常碰到这样的代码: jquery $.each(data, function (index, value) {    }) 遍历处理data,可以是数组.DOM.json等,取决于直接给 ...

  8. 百度之星IP聚合(水题map&字符处理)

    虽然题目停水的,但是好像字符处理运用的还比较合适 Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊 ...

  9. codeforces 659C C. Tanya and Toys(水题+map)

    题目链接: C. Tanya and Toys time limit per test 1 second memory limit per test 256 megabytes input stand ...

随机推荐

  1. 登录网站爬虫(保持Cookie不变)

    平时经常需要到学校的信息门户去查看课表及其他信息,于是想做一个爬虫 ,可以自动替我登录并且得到这些信息,于是今天动手写了一个爬虫: 首先登录学校的信息门户:http://cas.whu.edu.cn/ ...

  2. 【开源java游戏框架libgdx专题】-13-开发工具-地图的使用

    支持libGDX的地图编辑器有很多种,其中比较常用的工具为Tiled地图工具.Tiled是一款非常好用的地图编辑器.下载地址:http://www.mapeditor.org TiledMap类: 又 ...

  3. HDU5327

    #include <iostream> #include <stdio.h> #include <cstring> using namespace std; int ...

  4. 触发TreeView的TreeNodeCheckChanged事件

    这个事件不会主动postback,需要手动写javascript触发.对网上找到的方法做了些改进,增加UpdatePanel,以免页面不停的刷.这里就不考虑性能神马的了,因为既然项目已经允许选择使用T ...

  5. c# 使用递归 循环遍历导航树结构 并解析

    1.数据书库结构 1 家用电器 0 一级菜单 2 手机.数码.京东通信 0 一级菜单 3 电脑.办公 0 一级菜单 4 家具.家居.厨房 0 一级菜单 5 男装.女装.童装.内衣 0 一级菜单 6 个 ...

  6. 《InsideUE4》UObject(三)类型系统设定和结构

    垃圾分类,从我做起! 引言 上篇我们谈到了为何设计一个Object系统要从类型系统开始做起,并探讨了C#的实现,以及C++中各种方案的对比,最后得到的结论是UE采用UHT的方式搜集并生成反射所需代码. ...

  7. 你好,C++(31)我终于找到对象啦!6.1 从结构化设计到面向对象程序设计

    第6章 当C++爱上面向对象 很多第一次进入C++世界的人都会问:C++中的那两个加号到底是什么意思啊? C++是由C语言发展而来的,它比C语言多出的两个加号,实际上是C语言的自增操作符,表示C++语 ...

  8. jquery 文本框聚焦文字删除

    做作业需要,自己写了一个,写的很烂. $(function() { $("#search_input").addClass("before_focus");/* ...

  9. 富文本web编辑器(UEditor)

    展示效果:

  10. js循环便利json数据

    var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13},{name: ...