URAL 1915 Titan Ruins: Reconstruction of Bygones (栈)

Linux:安装Debian最新10.x操作系统(超详细) 安装Debian最新10.x操作系统安装Debian最新10.x操作系统1.下载Debian镜像2. 镜像安装引导启动页面,选择图形化安装:选择语言、时区,选中后点击continue:选择键盘模式:配置Hostname主机名,设置Root密码创建普通用户名和密码,进入磁盘分区步骤,选择“所有文件放在同一个分区”确认分区信息磁盘配置完,进入软件安装模块:选择源:进入软件包配置,等待配置结束根据需要选择软件包安装3. 安装完成重启后登录使用 安装Debian最新10.x操作系统 1.下载Debian镜像 下载D 阅读详情

1915. Titan Ruins: Reconstruction of Bygones



Time limit: 1.0 second
Memory limit: 64 MB
`It seems that we're in a trap,' said Soren.
`A very familiar phrase,' Alba replied.
The friends were locked in a room, which, apparently, had been a sort of laboratory where object copying experiments had been conducted. They decided so because there were large piles of coins in the room and the coins in each pile were identical to each other up to tiny scratches.
Soren studied the room and found a row of holes in one of the walls. The size of each hole was equal to the size of a coin, and he conjectured that the door would open when certain coins were put in the holes. At the same time, Alba examined the book on the table and discovered in it a description of an experiment with coins. In this experiment, coins were put one upon another forming a stack. Sometimes the top coin was removed, and sometimes the Copying Spell was applied, which produced an identical stack located on top of the existing stack.
Soren and Alba decided to repeat the experiment, putting the coins removed from the top of the stack into the holes one by one. They supposed that the door would open after that. However, they didn't know the Copying Spell, so they had to find out which coins were at top of stack without actual reproducing of all experiment. There were lots of various coins in the room they could use, but still it wasn't easy to choose which coins had to be put in the holes.

Input

The first line contains the number  n of operations in the experiment (1 ≤  n ≤ 10 6). In each of the following  n lines you are given an integer  x (−1 ≤  x ≤ 10 9). If  x > 0, then a coin of type  x is put on top of the stack. If  x = −1, then the top coin is taken from the stack and put into the next hole in the wall. If  x = 0, then the stack is copied. It is guaranteed that during the experiment each time a coin was to be removed the stack was not empty.

Output

Output the types of coins removed from the top of the stack in the course of the experiment. The numbers should be given one per line.

Sample

input output
8
3
4
0
-1
-1
-1
-1
1
4
3
4
3


开数组的技巧:够用就行,当栈足够大时,复制是多余的。


完整代码:

/*656ms,4236KB*/

#include <cstdio>

int stack[2000010];///开2*n大小

int main(void)
{
	int n, i, j, p, x;
	while (~scanf("%d", &n))
	{
		p = 0;
		for (i = 1; i <= n; i++)
		{
			scanf("%d", &x);
			if (x > 0)
				stack[p++] = x;
			else if (x < 0)
				printf("%d\n", stack[--p]);
			else if (p < n - i)///小技巧:当p足够大时,后面的复制是多余的
			{
				for (j = 0; j < p; j++)
					stack[j + p] = stack[j];
				p <<= 1;
			}
		}
	}
	return 0;
}



数学建模模型总结 这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助! 立即下载

相关推荐

从报错到定位:Memtest86 DQ位算法解析与实践指南

本文深入解析了Memtest86内存测试工具报错信息的解读方法,重点介绍了通过地址解析、数据转换、位比对和DQ定位四步算法,精准锁定故障DQ位的实践流程。文章以DDR4和DDR5为例,详细拆解了从十六进制报错到二进制比对的完整步骤,并提供了从单个报错分析到故障模式诊断的进阶指南,帮助用户将抽象的报错信息转化为具体的维修或排查依据。

sre5engineer的博客 486

UVA 12647 Balloon (线段树) URAL 1915 Titan Ruins: Reconstruction of Bygones (暴力,树状数组)

UVA 12647  Balloon (线段树)   URAL 1915 Titan Ruins: Reconstruction of Bygones (树状数组或暴力) 这两题都是转化后变成区间更新和点查询的问题(第二题是可以暴力的)!!! 第一题,转化为,区间覆盖,点值查询,(每个点记录的其上面一个线段的id) 第二题,转化为,区间加减值,点值查询,(每个点记录于其上一个点位置

冰 1819

手把手教你用Siemens EDA破解工具搞定PADs VX2.7安装与卡死问题

本文详细介绍了如何使用Siemens EDA工具解决PADs VX2.7的安装与卡死问题。从License配置到性能调优,提供全面的解决方案,帮助工程师高效完成电子设计自动化任务。特别针对常见的卡顿现象,给出了输入法兼容性调整、图形性能优化等实用技巧。

k8l9m0n的博客 554

ural 1915. Titan Ruins: Reconstruction of Bygones

翻译: 时间限制:1秒 空间限制: 64MB 对一个栈进行一些操作。详见下。 输入: 第一行一个整数N,操作总数。 接下来N行每行一个操作。若数大于0,代表将该数压栈。 若数等于-1,代表输出并抛弃栈顶元素。若为0,代表将目前栈内所有元素重新压栈。(就是复制一份栈) 输出: 每个-1操作时的栈顶元素。 样例输入: 8 3 4 0 -1 -1 -1 -1 1 样

Pegasus (http://ningning.today) 1264

of_graph_get_remote_port

isp { compatible = "isp"; core@0 { id = <0>; ports { #address-cells = <1>; #size-cells = <0>; port@0 { reg = <0>; ...

wmzjzwlzs的专栏 1166

保姆级教程:用NodeMediaClient在Android实现RTMP拉流播放(附避坑指南)

本文提供了一份详尽的Android平台RTMP拉流播放实现与深度调优指南。重点介绍了如何使用NodeMediaClient库进行集成,并针对视频卡顿、花屏等常见问题,从渲染引擎选择(SurfaceView与TextureView)、解码策略、缓冲区优化到高级网络自适应等方面提供了实战解决方案与避坑技巧。

weixin_29261711的博客 440

URAL 1915 Titan Ruins: Reconstruction of Bygones(思路)

搞这个题差不多是从比赛开始到结束。 从自信慢慢的看题一直到wrong到死。 这个题目可以说成是思路题,以为我们只要明白一点,这道题就成了纯暴力的水题, 那就是当操作数不足栈中数字数目的时候,我们就没有必要复制了。 注意数组要开足,如果是一路复制的话,2^20就可以到10^6次方级了,在cur 代码如下: #include #include #include #include #

稻草人 576

【华为OD机试真题】29、组成最大数 | 机试真题+思路参考+代码解析 (C++、Java、Py、C语言、JS)

题目描述 >小组中每位都有一张卡片,卡片上是6位内的正整数,将卡片连起来可以组成多种数字,计算组成的最大数字

KJ.JK 2419

C++ STL入门教程(4)——stack(栈),queue(队列),priority_queue(优先队列)的使用(附完整程序代码)

首先,这三者都是顺序容器适配器(适配器(adaptor)是根据原始的容器类型所提供的操作,通过定义新的操作接口,来适应基础的容器类型)。 本质上,适配器是使一事物的行为类似于另一事物的行为的一种机制。容器适配器让一种已存在的容器类型采用另一种不同的抽象类型的工作方式实现。 例如,假设deq是deque类型的容器,则可以用deq初始化一个新的栈: stack stk(deq);//带容器参数的

AC,∑ndless 3771

面向企业级应用的 SAP UI5 troubleshooting 全景指南:从日志与调试到性能与可测试性

本指南系统化介绍了SAP UI5应用排错的完整流程和工具链。从基础的浏览器开发者工具使用,到SAP UI5专用调试工具(Technical Information Dialog、Support Assistant、Diagnostics Window),再到性能优化和日志管理,提供了一套工程化的解决方案。重点推荐组合使用UI5 Inspector扩展、Test Recorder测试工具以及性能测量模块,并强调将常见问题整理成团队知识库。通过制度化的排错步骤和工具组合,开发者可以快速定位、复现和修复问题,将调

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 284

安路TangDynasty和FD和JTAG驱动器安装

安路FPGA产品矩阵包含SALPHOENIX高性能、SALEAGLE高性价比和SALELF低功耗三大系列,广泛应用于网络通信、消费电子等领域。配套的TangDynasty(TD)集成开发环境支持标准设计输入,提供完整优化流程与调试工具。简要介绍了TD 6.2.1版本的安装步骤。

wangjie36的博客 1039

URAL 1654 Cipher Message(栈)

1654. Cipher Message Time limit: 1.0 second Memory limit: 64 MB Müller tried to catch Stierlitz red-handed many times, but always failed because Stierlitz could ever find some excuse. Once

AC,∑ndless 2203

SAP UI5 主题设置全解析:从启动参数到运行时切换、跨域白名单与事件监听

SAP UI5主题体系深度解析:从配置到切换的完整指南 摘要:SAP UI5主题机制远不止CSS换肤,其工程化实践涵盖启动配置、运行时API切换、跨库路径映射及安全管控等关键环节。通过bootstrap标签或URL参数设置初始主题,运行时可用Theming.setTheme无刷新切换。自定义主题需配置theme-roots路径,跨域加载需声明sap-allowed-theme-origins白名单。主题切换完成后会触发applied事件,适合执行视觉同步操作。该体系支持多品牌适配、集中式主题管理,在Fior

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 327

POJ 2106 / México and Central America 2004 Boolean Expressions (用栈处理表达式)

Boolean Expressions http://poj.org/problem?id=2106 Time Limit: 1000MS Memory Limit: 30000K Description The objective of the program you are going to produce is to evaluate boolean e

AC,∑ndless 2094

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

UVa 673 Parentheses Balance (栈)

673 - Parentheses Balance Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=103&page=show_problem&problem=614 You are given a string consis

AC,∑ndless 2057

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

POJ 2559 / HDU 1506 / LightOJ 1083 Largest Rectangle in a Histogram (单调栈)

Largest Rectangle in a Histogram http://poj.org/problem?id=2559 Time Limit: 1000MS Memory Limit: 65536K Description A histogram is a polygon composed of a sequence of rectangles ali

AC,∑ndless 1991

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

POJ 1028 / East Central North America 2001 Web Navigation (栈)

Web Navigation http://poj.org/problem?id=1028 Time Limit: 1000MS Memory Limit: 10000K Description Standard web browsers contain features to move backward and forward among the p

AC,∑ndless 1666

UVa 442/HDU 1082/ZOJ 1094 Matrix Chain Multiplication(模拟&栈)

442 - Matrix Chain Multiplication Time limit: 3.000 seconds Suppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices. Since matrix multiplication is associative,

AC,∑ndless 1638

UVa 127 "Accordian" Patience (模拟链表&栈)

127 - "Accordian" Patience Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=103&page=show_problem&problem=63 You are to simulate the p

AC,∑ndless 1257

POJ 2796 Feel Good (单调栈)

http://poj.org/problem?id=2796 和POJ 2559一样,把计算矩形的长改为前缀和就行。 完整代码: /*891ms,2716KB*/ #include #include using namespace std; const int mx = 100005; __int64 h[mx], sum[mx]; int l[mx], r[mx];

AC,∑ndless 1151

HDU 1022 Train Problem I (栈)

Train Problem I http://acm.hdu.edu.cn/showproblem.php?pid=1022 Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others) Problem Description As the

AC,∑ndless 1095

UVa 11995 I Can Guess the Data Structure! (STL)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3146 注意“without error”这句。 /*0.038s*/ #include #include #include using namespace st

AC,∑ndless 927

深挖C++:类和对象(中)

(先进后出)

xys_678的博客 250

ThunderKittens 深度解析:一个不基于 MLIR 的 C++ 模板 GPU DSL

Triton 是"让更多人能写 GPU kernel",ThunderKittens 是"让会写的人写得更爽"。前者用 MLIR 换易用性,后者用 C++ 模板换可控性。它们不是替代关系,而是覆盖了 GPU 编程光谱的两端。ThunderKittens 的出现,本质上是对"GPU DSL 必须基于 MLIR"这一默认假设的挑战。编译期类型系统本身就可以是一个强大的 DSL 基础设施,不需要中间 IR,不需要黑盒 pass,也能实现 tile 级抽象和零运行时开销。

Maxwell_Newton的博客 346

C++移动构造函数详解

移动构造函数是C++11引入的一种特殊构造函数,用于从临时对象(右值)"窃取"资源来初始化新对象,而不是进行昂贵的深拷贝。char* data;public:// 移动构造函数:参数是右值引用 &&// 关键:把源对象的资源置空。

拒绝AI文,努力在AI时代写出感动人心的好文章 394
上一篇: Codeforces Round #152 (Div. 2) / 248B Chilly Willy (数论)
下一篇: Codeforces Round #198 (Div. 2) / 340A The Wall (数论)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值