HDU 1990 Monkey Vines (瞎搞)
来源:互联网 发布:水文气象数据的重要性 编辑:程序博客网 时间:2024/05/01 19:30
Monkey Vines
Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 451 Accepted Submission(s): 232
Problem Description
Deep in the Amazon jungle, exceptionally tall trees grow that support a rich biosphere of figs and juniper bugs, which happen to be the culinary delight of brown monkeys.
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.
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.
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
Source
2008 “Shun Yu Cup” Zhejiang Collegiate Programming Contest - Warm Up(1)
Recommend
linle | We have carefully selected several similar problems for you: 1993 1992 1991 1711 1517
题意:这题好难读....读了好久才懂...英语太渣....读懂题目发现好水...
有一棵完整的二叉树,下面有一群猴子。要求出最小的猴子数量,来使这棵二叉树是平衡的。平衡就是指同一个父节点下面两个儿子节点上面呆的猴子数量必须相同。还有这个树上至少要有一只猴子。
题解:如果想要二叉树上平衡,取决于最深的节点的深度。2^dep 就是最少需要多少只猴子来平衡这棵树。因为输入的时候,是用括号来表示这棵树的。左括号表示向下延伸,右括号表示回到父亲节点。注意这棵二叉树的根的上面还有一个根。所以要从图片中的黑色实心半球开始。所以求深度,只要一次线性扫描就行了,左括号+,右括号-。求出最深的深度dep。然后2*dep。。。。
AC代码:
#include<bits/stdc++.h>using namespace std; int main(){int t; int cas=1; char str[500];int ans,dep;scanf("%d",&t);getchar();while(t--){gets(str);ans=0;dep=0;for(int i=0;str[i];i++){if(str[i]=='[')dep++;else dep--;if(dep>ans)ans=dep;}int res=1;for(int i=0;i<ans;i++){res*=2;}printf("%d %d\n",cas++,res);}return 0;}
1 0
- HDU 1990 Monkey Vines (瞎搞)
- HDU 1990 & ZOJ 2992 Monkey Vines(数学啊)
- ZOJ2992 HDU1990 Monkey Vines
- TOJ Monkey Vines
- Sicily 1525. Monkey Vines
- TOJ 3009.Monkey Vines
- 南邮 OJ 1399 Monkey Vines
- ZJU2992 Monkey Vines - 二叉树 推规律
- zoj zju 2992 Monkey Vines 二叉树
- HDU 5000 Clone(瞎搞)
- HDU 4940 Destroy Transportation system (瞎搞)
- 【瞎搞】 HDU 1986 Encoding
- 【瞎搞】HDU 5124 lines
- 【瞎搞】 HDU 5312 Sequence
- HDU 4970(杭电多校#9 1011题)Killing Monsters(瞎搞)
- HDU 4961(杭电多校#9 1002题)Boring Sum(瞎搞)
- HDU 5194 DZY Loves Balls(排列组合瞎搞 )
- HDU 1061 Rightmost Digit 【快速幂 Or 规律(瞎搞)】
- 黑客软件编写基础知识锦囊2
- 洛谷 P1314 聪明的质监员
- 自定义MyBatis日志
- linux root密码找回
- Google's BBR拥塞控制算法模型解析
- HDU 1990 Monkey Vines (瞎搞)
- jsp中文乱码六种情况---解决方案
- 红星美凯龙的笔试和面试
- hbase shell基础和常用命令详解(转)
- 进制转换
- 鼠标经过选项,浅色边框变成红色边框,原来的浅色竖线被覆盖;尽量但是不改变原来选项的盒子的大小的方法;如图效果
- COM学习--1.COM对象标识
- HBase体系结构(转)
- HBase Java API类介绍