UVA11111Generalized Matrioshkas
来源:互联网 发布:程序员工作累吗? 编辑:程序博客网 时间:2024/06/03 17:56
UVA-11111
题意:大玩具里面可以塞小玩具,但是小玩具的体积和要小于 ( 没有等于!! ) 大玩具的体积。-n+n表示一个玩具,-7 -3 +3 +7表示一个体积为7的玩具里面塞来一个体积为3的玩具。判断给出的串合不合法。
解体思路:符号匹配 2.0。符号为- 时将n进栈,符号为+时出栈n,并在包含它的那个玩具的已装容量内增加n。当n出栈时判断容量是否大于已装容量。
/************************************************************************* > File Name: UVA-11111.cpp > Author: Narsh > > Created Time: 2016年07月16日 星期六 14时11分33秒 ************************************************************************/#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;struct node{ int x,w;}t[30000];int l,n;char c;int main () { while (scanf("%d%c",&n,&c) !=EOF) { l = 1; t[l].x =-n; t[l].w = 0; while (c !='\n') { scanf("%d%c",&n,&c); if (n < 0) { t[++l].x=-n; t[l].w=0; } if (n > 0) { if ( t[l].x == n && t[l].w < t[l].x) { l--; t[l].w +=t[l+1].x; } } } if (!l) printf(":-) Matrioshka!\n"); else printf(":-( Try again.\n"); }}
0 0
- UVA11111Generalized Matrioshkas
- Generalized Matrioshkas
- poj3195 Generalized Matrioshkas(栈)
- uva 11111 - Generalized Matrioshkas
- UVa 11111 Generalized Matrioshkas
- uva 11111 - Generalized Matrioshkas
- uva 11111 - Generalized Matrioshkas
- UVa 11111 - Generalized Matrioshkas
- 11111 - Generalized Matrioshkas
- uva 11111 - Generalized Matrioshkas
- UVa 11111 - Generalized Matrioshkas
- UVaOJ11111---Generalized Matrioshkas
- UVA-11111-Generalized Matrioshkas
- uva 11111 - Generalized Matrioshkas
- uva-11111 Generalized Matrioshkas
- UVa 11111 - Generalized Matrioshkas
- 11111 - Generalized Matrioshkas
- UVA 11111 Generalized Matrioshkas
- Android Studio中Intel HAXM的那些坑
- Android setCompoundDrawables无效
- 嵌入式学习-linux系统-lesson2-内核相关
- 元素节点、属性节点、文本节点 的节点属性
- Learning Python 008 正则表达式-002 findall()方法
- UVA11111Generalized Matrioshkas
- VPNservice
- 图解 head first 设计模式
- Mybatis深入了解(五)----动态SQL
- Codeforces 689D Friends and Subsequences (RMQ+二分)
- 退出后点击浏览器后退不能回到成功页面;直接进入页面和跳转进入页面样式不同;防止直接输入页面地址或servlet;当servlet跳servlet时,进行其他操作后后退出现错误!
- android中wifi原理及流程分析(很经典)
- 【DRP】-servlet 请求传值
- 实例:创建、启动、停止和绑定一个Service