TOJ Monkey Vines
来源:互联网 发布:分手后做朋友 知乎 编辑:程序博客网 时间:2024/05/17 01:17
Reaching the canopy of these trees requires the monkeys to perform careful navigation through the tall tree's fragile vine system. These vines operate like a see-saw: an unbalancing of weight at any vine junction would snap the vine from the tree, and the monkeys would plummet to the ground below. The monkeys have figured out that if they work together to keep the vines properly balanced, they can all feast on the figs and juniper bugs in the canopy of the trees.
A vine junction supports exactly two sub-vines, each of which must contain the same number of monkeys, or else the vine will break, leaving a pile of dead monkeys on the jungle ground. For purposes of this problem, a vine junction is denoted by a pair of matching square brackets [ ], which may contain nested information about junctions further down its sub-vines. The nesting of vines will go no further than 25 levels deep.
You will write a program that calculates the minimum number of monkeys required to balance a particular vine configuration. There is always at least one monkey needed, and, multiple monkeys may hang from the same vine.
Input
The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.Each dataset consists of a single line of input containing a vine configuration consisting of a string of [ and ] characters as described above. The length of the string of [ and ] will be greater than or equal to zero, and less than or equal to 150.
Output
For each dataset, you should generate one line of output with the following values: The dataset number as a decimal integer (start counting at one), a space, and the minimum number of monkeys required to reach the canopy successfully. Assume that all the hanging vines are reachable from the jungle floor, and that all monkeys jump on the vines at the same time.Sample Input
3[][[][[]]]
Sample Output
1 22 13 8
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;int main(){int n,dep,r,i,l,s;char a[151];cin>>n;getchar();for(i=1;i<=n;i++){gets(a);l=strlen(a);dep=0;r=0;for(int j=0;j<l;j++){if(a[j]=='[')dep++;else if(a[j]==']')dep--;if(r<dep)r=dep;}s=1;for(int j=0;j<r;j++){s=s*2;}cout<<i<<" "<<s<<endl;}return 0;}
- TOJ Monkey Vines
- TOJ 3009.Monkey Vines
- ZOJ2992 HDU1990 Monkey Vines
- Sicily 1525. Monkey Vines
- 南邮 OJ 1399 Monkey Vines
- ZJU2992 Monkey Vines - 二叉树 推规律
- zoj zju 2992 Monkey Vines 二叉树
- HDU 1990 Monkey Vines (瞎搞)
- HDU 1990 & ZOJ 2992 Monkey Vines(数学啊)
- monkey
- monkey
- monkey
- Monkey
- Monkey
- monkey
- monkey
- monkey
- Monkey
- 编译原理手记04-通过状态图设计词法分析器
- Python 环境设置 配置 入门
- Shell的基本应用--简介及启动
- linux 下连接mysql服务器
- LR report模板的运用
- TOJ Monkey Vines
- vdfvfdvfv
- UCF 大牛 Prof. Shah 课题组代码合集
- TOJ 1563 Round and Round We Go (弃9数)
- java中变量、对象的存储位置
- java 压缩图片实例
- 数据结构 栈
- STL源码剖析 容器 stl_tree.h
- [NWPU][2014][TRN][6]动态规划第一讲——简单线性dp_C题