当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4874:ZCC Loves RPG

题目描述
ZCC is playing a RPG game named “kenji’s life VI”.
In this game, as an advanturer, ZCC has N kinds of energy, labeled 1 to N. Before set off for an adventure, ZCC can charge some of his energy, which allow he to set the amount of every kind of energy (a_i) a non-negative integer arbitrarily. Different kind of energy is set independently.
When different energy mix, they become unstable. If there exist two integers u and v (u≤v), where a_u, a_u+1, ..., a_v are all positive number, and sum of those v-u+1 number exceed K, a horrific explosion occurs, and of course, Game Over.
During the adventure, the story may develop differently depending on the amount of a certain kind of energy. Sometimes there will be some CGs, but some of CGs may only appear in some certain sub-story.
ZCC has played this game many times, but failed to collect some of the CGs. Now he wonders, How many kinds of CGs is collectable?
The Scenario is given in the form of C++ like code.

As an explanation:
The Scenario is presented as a non-type function game(n, k).
game(n, k) has 2 arguments, n and k, which are actually 2 constants. n is the number of energy type available, k is the limitation of sum of consecutive positive number. There may be 3 types of statement:
1.cg(p1), means a CG numbered p1 appears here.
2.if (a[p1] >= p2) <statement> [else <statement>], is just like the branch statement in other programming languages. else is matched with the nearest if, just like the way C++ works.
3.{ <statements>* }, a block contains zero, one or several statements.
Note that though the scenario is guaranteed to satisfy the grammar above, the code-style(space, bracket, line break) may not strictly obeys the explanation above.
输入解释
A scenario with total length do not exceed 3MB.
It’s guaranteed:
n≤10^5;
in cg(p1), p1 is a non-negative number between 0 and 2^20-1;
in if (a[p1] >= p2), 1≤p1≤n,0≤p2≤10^9.
输出解释
An integer: the number of CGs collectable.
输入样例
game(3, 1){
  cg(0);
  if (a[1] >= 1)
    cg(1);
  else if (a[1] >= 2) cg(2);
  if (a[2] >= 1)
    if (a[3] >= 1) cg(3); 
    else cg(4);
  {cg(0);}
}
输出样例
3

提示
CGs collectable are CG#0, CG#1 and CG#4.
Though CG#0 appears 2 times, the answer is 3, instead of 4.
来自杭电HDUOJ的附加信息
Author 镇海中学
Recommend

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-4874

最后修改于 2020-10-25T23:17:40+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 130712/130712K(Java/Others)