HDU 1990 & ZOJ 2992 Monkey Vines(数学啊)
来源:互联网 发布:js如何清空div的内容 编辑:程序博客网 时间:2024/05/17 08:01
题目链接:
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1990
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1991
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
代码如下:
#include <cstdio>#include <cstring>int main(){ int t; int cas = 0; char s[1117]; scanf("%d",&t); getchar(); while(t--) { //scanf("%s",s); gets(s); int len = strlen(s); int k = 0; int maxx = 0; for(int i = 0; i < len; i++) { if(s[i] == '[') k++; else k--; if(k > maxx) maxx = k; } printf("%d %d\n",++cas,1<<maxx); } return 0;}
1 0
- HDU 1990 & ZOJ 2992 Monkey Vines(数学啊)
- HDU 1990 Monkey Vines (瞎搞)
- zoj zju 2992 Monkey Vines 二叉树
- ZOJ2992 HDU1990 Monkey Vines
- TOJ Monkey Vines
- Sicily 1525. Monkey Vines
- TOJ 3009.Monkey Vines
- 南邮 OJ 1399 Monkey Vines
- HDU 1985 & ZOJ 2988 Conversions(数学啊)
- ZJU2992 Monkey Vines - 二叉树 推规律
- hdu 1512 Monkey King and ZOJ 2334
- ZOJ 2334 HDU 1512 Monkey King
- HDU 1988 & ZOJ 2991 Flipping Burned Pancakes(数学啊+模拟)
- HDU 5201 The Monkey King (容斥+数学组合+隔板法)
- zoj 3041 City Selection(数学啊)
- ZOJ 3180 Number Game(数学啊 )
- ZOJ 3488 Conic Section(数学啊 )
- ZOJ 3327 Friend Number(数学啊 )
- struts2的拦截器
- Qt国际化——多语言翻译时值得注意的一个编程问题
- [nginx]centos6.5下nginx-1.6.2的安装,与tomcat简单整合
- HDOJ 1017 A Mathematical Curiosity
- 动态注册native函数
- HDU 1990 & ZOJ 2992 Monkey Vines(数学啊)
- Hadoop数据类型
- 如何在Visual Studio中调试.NET源码
- 网络基本功(二十三):Wireshark抓包实例诊断TCP连接问题
- java连接access数据库说明以及示例代码
- 工业4.0:中国需要补课么?
- printf 一些使用细节
- UI自动化测试介绍
- JSONP存在的JSON Hijacking漏洞以及与csrf/xss漏洞的关系