1220. Stacks
又一神题啊 卡内存可以卡到这种地步 省得不行了
开两个【N]数组 一个来记录前驱 一个存数 记录前驱的用unsigned short类型 最大可达65535 不过可以标记一下是否比这个数大 比它大的话就减去 求的时候再加上
#include <iostream>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cstdio>
using namespace std;
#define N 100010
unsigned short p2[N];
int p1[N];
int stack[];
int main()
{
int n,a,b,g=;
char s[];
scanf("%d",&n);
while(n--)
{
scanf("%s",s);
if(strcmp(s,"PUSH")==)
{
scanf("%d%d%*c",&a,&b);
p1[g] = b;
if(stack[a]>=)
{
p2[g] = stack[a]-;
p1[g] = -p1[g];
}
else
p2[g] = stack[a];
stack[a] = g;
g++;
}
else
{
scanf("%d%*c",&a);
printf("%d\n",abs(p1[stack[a]]));
if(p1[stack[a]]<)
stack[a] = p2[stack[a]]+;
else
stack[a] = p2[stack[a]];
}
}
return ;
}
1220. Stacks的更多相关文章
- [LeetCode] Implement Queue using Stacks 用栈来实现队列
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...
- Leetcode Implement Queue using Stacks
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...
- Device nodes and device stacks
[Device nodes and device stacks] 链接:https://msdn.microsoft.com/en-us/library/windows/hardware/ff5547 ...
- 1220 - Mysterious Bacteria--LightOj1220 (gcd)
http://lightoj.com/volume_showproblem.php?problem=1220 题目大意: 给你一个x,求出满足 x=b^p, p最大是几. 分析:x=p1^a1*p2^ ...
- 2016暑假多校联合---Joint Stacks (STL)
HDU 5818 Problem Description A stack is a data structure in which all insertions and deletions of e ...
- openstack-kilo--issue(九) heat stacks topology中图形无法正常显示
======声明======= 欢迎转载:转载请注明出处 http://www.cnblogs.com/horizonli/p/6186581.html ==========环境=========== ...
- Implement Queue using Stacks
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...
- Bitnami --https://bitnami.com/stacks
Bitnami is an app store for server software. Install your favorite applications in your own servers ...
- poj 1220(短除法)
http://poj.org/problem?id=1220 题意:进制转换,把a进制转换为b进制. 如果数据不大的话,那么这个题还是很简单的,但这个题就是数据范围太大,所以这里可以采用短除法来做. ...
随机推荐
- 关于canvas中的jquery
关于h5,相比前端的同事们都很了解了吧!h5里面有个canvas,现在用的蛮火.但是canvas里面的代码确实是有点繁多,特别是要对于图形做什么操作的时候...我昨天无意间发现了一个canvas的插件 ...
- undefined local variable or method ‘xxx’ for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xbc88d6c>错误解决方案
官方文档如下: https://github.com/rspec/rspec-rails/blob/master/Capybara.md Capybara 2.0 To use Capybara 2. ...
- 完美解决IE6中fixed抖动问题的方法
我们可以通过position:fixed来实现元素的固定效果,如网页中底部的"回到顶部菜单",底部的toolbar,对联广告等等,可惜fixed属性在IE6及以下是不支持的.通常的 ...
- (转载)异构数据库之间完全可以用SQL语句导数据
<来源网址:http://www.delphifans.com/infoview/Article_398.html>异构数据库之间完全可以用SQL语句导数据 告诉你一个最快的方法,用SQL ...
- epoll_create, epoll_ctl和epoll_wait
参考代码 #include <iostream> #include <sys/socket.h> #include <sys/epoll.h> #include & ...
- FFT Golang 实现
最近项目要用到快速傅立叶变换,自己写了个算法,测试了下,性能和精度还可以接受 len,time= 1048576 378.186167ms diff=-0.00000000000225974794 I ...
- (转)Qt Model/View 学习笔记 (二)——Qt Model/View模式举例
Qt Model/View模式举例 Qt提供了两个标准的models:QStandardItemModel和QDirModel.QStandardItemModel是一个多用途的model,可用于表示 ...
- HDFS导论(转)
1.流式数据访问 HDFS的构建思想是这样的:一次写入,多次读取是最高效的访问模式.数据集通常有数据源生成或从数据源复制而来,接着长时间在此数据集上进行各类分析.每次分析都将设计数据集的大部分数据甚至 ...
- Deep Learning and the Triumph of Empiricism
Deep Learning and the Triumph of Empiricism By Zachary Chase Lipton, July 2015 Deep learning is now ...
- JUnit 4 使用 Java 5 中的注解(annotation)
JUnit 4 使用 Java 5 中的注解(annotation),以下是JUnit 4 常用的几个 annotation 介绍@Before:初始化方法@After:释放资源@Test:测试方法, ...