先看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. 【开源java游戏框架libgdx专题】-08-中文显示与绘制

    libgdx虽然是由美国人Mario Zechner(即BadlogicGames)写的开源引擎,由于Libgdx底层是用OpenGL实现的,所以Libgdx是可以支持中文的,在libgdx中的汉字都 ...

  2. J2EE初探

    J2EE概述 3层结构 4层模型 13项核心技术 J2EE容器 J2EE的优势与缺陷   J2EE概述 Java 2平台有3个版本,分别是适用于小型设备和智能卡的Java 2平台Micro版(Java ...

  3. [个人原创]关于java中对象排序的一些探讨(二)

    2.  使用Collections.sort()方法 Collections类中提供了诸多静态方法,诸如addAll(),max()等等.当自己相对Collection接口下的类处理的时候,可以看看这 ...

  4. firebug js版

    1.有些时候如 ie6 7 8 你觉得F12 不好用的话  你可以直接 把这两个js 引用到html 里面 <script src="https://getfirebug.com/fi ...

  5. DOM中的node与element的区别

    先看document的两个常见method. document.createTextNode Constructor: Text document.createElement Constructor: ...

  6. JavaScript 框架比较

    显著增强 JavaScript 开发的框架概览 Joe Lennon, 软件开发人员, 自由职业者 简介: 现代 Web 站点和 Web 应用程序倾向于依赖大量客户端 JavaScript 来提供丰富 ...

  7. 面向对象设计模式之TemplateMethod模板方法(行为型)

    动机:在软件构建过程中,对于某一项任务,他常常有稳定的整体操作结构,但各个子步骤却有很多改变的需求,或者由于固有的原因(比如框架与应用之间的关系)而无法和任务的整体结构同时实现:如何在确定稳定操作结构 ...

  8. PHP实现动态生成饼状图、柱状图和折线图(转载)

    PHP在图像操作方面的表现非常出色,我们只需借助可以免费得到的GD库便可以轻松实现图.表勾画.下面将分别介绍PHP实现的饼状图.折线图和柱状图以 及他们的使用方法,这几段代码的特点就是不需要再把它们复 ...

  9. ie6789和其他浏览器之间的鼠标左、中、右键的event.button不一致的办法

      左键 中键 右键 Ie6 1 4 2 Ie7 1 4 2 Ie8 1 4 2 Ie9和其它 0 1 2 以下代码将IE6/7/8的值转换成符合W3C标准的方法: var ie678 = !-[1, ...

  10. sql server 调优----索引未使用

    SELECT TOP 1000o.name AS 表名, i.name AS 索引名, i.index_id AS 索引id, dm_ius.user_seeks AS 搜索次数, dm_ius.us ...