链接:https://codeforces.com/contest/1175/problem/B

题意:

You are given a function ff written in some basic language. The function accepts an integer value, which is immediately written into some variable xx. xx is an integer variable and can be assigned values from 00 to 232−1232−1. The function contains three types of commands:

  • for nn — for loop;
  • end — every command between "for nn" and corresponding "end" is executed nn times;
  • add — adds 1 to xx.

After the execution of these commands, value of xx is returned.

Every "for nn" is matched with "end", thus the function is guaranteed to be valid. "for nn" can be immediately followed by "end"."add" command can be outside of any for loops.

Notice that "add" commands might overflow the value of xx! It means that the value of xxbecomes greater than 232−1232−1 after some "add" command.

Now you run f(0)f(0) and wonder if the resulting value of xx is correct or some overflow made it incorrect.

If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of xx.

思路:

模拟,我用递归写的。

用stack也可以

代码:

#include <bits/stdc++.h>
using namespace std;typedef long long LL;
const unsigned int MAXV = (1LL<<32)-1;
const int MAXN = 1e5+10;
int n;
bool flag = true;struct Op
{string op;LL va;
}oper[MAXN];
int step = 1;LL Dfs(LL lops)
{if (step > n)return 0;LL res = 0;while (oper[step].op[0] == 'a'){step++;res++;}
//    cout << "res1:" << res << endl;while (oper[step].op[0] == 'f'){res += Dfs(oper[step++].va);if (res > MAXV)flag = false;while (oper[step].op[0] == 'a'){step++;res++;}}
//    cout << "res2:" << res << endl;if (1LL*lops*res > MAXV)flag = false;
//    cout << "res3:" << lops*res << ' ' << step << endl;step++;return lops*res;
}int main()
{
//    freopen("test.in", "r", stdin);cin >> n;for (int i = 1;i <= n;i++){cin >> oper[i].op;if (oper[i].op[0] == 'f')cin >> oper[i].va;}LL res = Dfs(1);if (!flag)cout << "OVERFLOW!!!" << endl;elsecout << res << endl;return 0;
}

  

转载于:https://www.cnblogs.com/YDDDD/p/10984224.html

Educational Codeforces Round 66 (Rated for Div. 2) B. Catch Overflow!相关推荐

  1. Educational Codeforces Round 66 (Rated for Div. 2)

    题意:求最小操作数 使得归零   两种操作 1 减一   2能被k整除的时候除k 签到题: 记得开ll即可 #include<bits/stdc++.h> using namespace ...

  2. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

  3. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  4. Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...

  5. Educational Codeforces Round 37 (Rated for Div. 2) 1

    Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...

  6. Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)

    Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...

  7. Educational Codeforces Round 114 (Rated for Div. 2) D. The Strongest Build 暴力 + bfs

    传送门 文章目录 题意: 思路: 题意: 你有nnn个装备槽,每个槽里面有cic_ici​个力量加成,对于每个槽只能选一个力量加成,现在给你mmm个力量组合[b1,b2,...,bn][b_1,b_2 ...

  8. Educational Codeforces Round 72 (Rated for Div. 2) D. Coloring Edges dfs树/拓扑找环

    传送门 文章目录 题意: 思路: 题意: 给你一张图,你需要给这个图的边染色,保证如果有环那么这个环内边的颜色不全相同,输出染色方案和用的颜色个数. n,m≤5e3n,m\le5e3n,m≤5e3 思 ...

  9. Educational Codeforces Round 111 (Rated for Div. 2) D. Excellent Arrays 组合数学

    传送门 文章目录 题意: 思路: 题意: 给你一个数组aia_iai​,定义一个数组是好的当且仅当对于所有iii都有ai!=ia_i!=iai​!=i.定义f(a)f(a)f(a)表示数组aaa中i& ...

最新文章

  1. C++ STL 基本使用Win32 版
  2. 计算机网络第四章-网络层复习笔记
  3. Activity 与ListActivity的区别
  4. 2015. A New Year Gift
  5. win配置环境变量以及一些变量换行类的小技巧
  6. Visual C++ 设置适合自己的解决方案目录结构
  7. linux 查看进程变量,Linux下查看进程(程序)启动时的环境变量
  8. 手机锁屏js倒计时停止问题解决办法探索
  9. java流程控制结构不包括_以下各项中不属于Java语言流程控制结构的是()。
  10. 如何进行cad地理配准_地理配准和空间校正操作流程
  11. CALayer和Retina显示屏的高分辨率的支持
  12. win10系统cpu内核或逻辑核心缺少缺少,解决办法
  13. 电脑上如何进行MP4格式转换成其它格式?
  14. 华为核心交换机HW_S7706添加静态路由
  15. 计算机课件制作总结,课件制作比赛活动总结范文
  16. html获取微信code,微信授权获取code(微信支付)
  17. ios设备管理软件imazing 2.16.2官网下载,2022年强悍来袭!
  18. 深度学习的趣味app简单优化(适合新手)
  19. PT100热电阻温度传感器 铂热电阻 德国贺利氏 硅胶四氟镀锡屏蔽线
  20. python0x452_python at 0x

热门文章

  1. pta7-3 统计不及格人数_编写程序,统计学生的成绩信息
  2. Java的scjp_java scjp
  3. java风控系统规则引擎_如何设计一套规则引擎系统
  4. :empty css 可以用在哪些标签,CSS伪类:empty让我眼前一亮(实例代码)
  5. java 图像 截取正方形,Instagram API仅返回正方形(裁剪)图像
  6. java acr122 读取数据_使用ACR122U 从NTAG203Chip 读取数据
  7. c 多线程mysql_多线程读写mysql数据库
  8. FPGA之道(1)HDL代码风格
  9. unity 游戏第一次安装完之后运行,切出来,点击桌面图标后黑屏问题
  10. BZOJ4034 树上操作(树剖 线段树大模板)