【题目链接】

点击打开链接

【算法】

其实这就是一道模拟题啦!

在判error和计算时间复杂度时,我们需要用栈这种数据结构

【代码】

这题的代码还是有些难写的,写的时候一定要有条理!

#include<bits/stdc++.h>
using namespace std;
#define MAXL 100
const int INF = 2e9; int T,n;
char opt[MAXL+],value[MAXL+];
int l[MAXL+],r[MAXL+]; template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
} inline int get() {
int ret = ;
bool b = true;
getchar();
char c = getchar();
while (c != ')') {
if (c == '^') b = false;
if (isdigit(c)) ret = (ret << ) + (ret << ) + c - '';
c = getchar();
}
getchar();
if (b) return ;
else return ret;
} inline void getstr(int pos) {
char c = getchar();
while (c != 'F' && c != 'E') c = getchar();
opt[pos] = c;
} inline void getinfo(int pos) {
int i,len;
char tx[],ty[];
getstr(pos);
if (opt[pos] == 'E') return;
scanf(" %c %s %s",&value[pos],tx+,ty+);
if (tx[] != 'n') {
len = strlen(tx+);
for (i = ; i <= len; i++) l[pos] = (l[pos] << ) + (l[pos] << ) + tx[i] - '';
} else
l[pos] = INF;
if (ty[] != 'n') {
len = strlen(ty+);
for (i = ; i <= len; i++) r[pos] = (r[pos] << ) + (r[pos] << ) + ty[i] - '';
} else
r[pos] = INF;
getchar();
} inline bool error() {
int i,top=;
static int stk[MAXL+];
static bool used[];
memset(used,,sizeof(used));
for (i = ; i <= n; i++) {
if (opt[i] == 'F') {
if (used[value[i]-'a']) return true;
used[value[i]-'a'] = true;
stk[++top] = i;
} else {
if (!top) return true;
used[value[stk[top]]-'a'] = false;
--top;
}
}
return top != ;
} inline void solve() {
int i,top=,c,tmp,ans=;
static int stk[MAXL+];
memset(l,,sizeof(l));
memset(r,,sizeof(r));
read(n);
c = get();
for (i = ; i <= n; i++) getinfo(i);
if (error()) {
puts("ERR");
return;
}
for (i = ; i <= n; i++) {
if (opt[i] == 'F') {
tmp = stk[top];
if (l[i] > r[i]) tmp = -;
else if (r[i] - l[i] > && stk[top] != -) ++tmp;
stk[++top] = tmp;
ans = max(ans,tmp);
} else
--top;
}
if (ans == c) puts("Yes");
else puts("No");
} int main() { read(T);
while (T--) solve(); return ;
}

【NOIP2017 DAY1T2】 时间复杂度的更多相关文章

  1. 洛谷【P3952】NOIP2017提高组Day1T2时间复杂度

    我对模拟的理解:http://www.cnblogs.com/AKMer/p/9064018.html 题目传送门:https://www.luogu.org/problemnew/show/P395 ...

  2. NOIP 2017 提高组 day1t2 时间复杂度

    P3952 时间复杂度 标签 NOIp提高组 2017 时空限制 1000ms / 128MB 小明正在学习一种新的编程语言 A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂 ...

  3. NOIP2017 d1t2 时间复杂度

    题目传送门:洛谷P3952 大模拟不解释 #include<iostream> #include<cstdio> #include<cmath> #include& ...

  4. NOIP2017 D1T2时间复杂度

    这道题在考试时看到感觉与第一题放反了位置(因为我还没有看到第一题是结论题) 对于每个语句进行栈的模拟,而如果有语法错误就特判. 对于每一条for语句我们将其与栈顶元素连边,复杂度是1的我们不用考虑,如 ...

  5. luogu 3952 时间复杂度

    noip2017 D1T2 时间复杂度 某zz选手考场上写了1.5h 考完之后发现自己写的是错的 但是结果A了??? 题目大意: 一种新的编程语言 A++ 给出一个程序只有循环语句 并给出这个程序的时 ...

  6. $NOIp$提高组做题记录

    对了我在这里必须讲一个非常重要的事情,就是前天也就是$2019.8.21$的傍晚,我决定重新做人了$!!$ 其实之前没怎么做$Noip$题,那就从现在开始叭

  7. 【比赛】NOIP2017 时间复杂度

    恶心的模拟题,考场上犯了一堆错误,多组数据清空没清完.数组开小...民间都是50分,结果CCF90.. 考完后随便改改就过了,还好只少了10分,如果真的是50,我估计会疯掉. 因为考场的时候没写好,所 ...

  8. [Luogu 3952] NOIP2017 时间复杂度

    [Luogu 3952] NOIP2017 时间复杂度 一年的时间说长不长,说短,也不短. 一年之内无数次觉得难得可怕的题目,原来也就模拟这么回事儿. #include <cstdio> ...

  9. P3952 NOIP2017 时间复杂度

    写了两三个小时,麻烦倒是不麻烦,要考虑清楚,想全了 只过了样例提交是不是傻,要自己造数据 数据不大可以用STL 建议自己刚一下,不看代码 #include <iostream> #incl ...

随机推荐

  1. codevs——1501 二叉树最大宽度和高度

    1501 二叉树最大宽度和高度  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解       题目描述 Description 给出一个二叉树,输出它的 ...

  2. 浅谈Java字符串

    从概念上而言,Java字符串就是Unicode字符序列.由于Java没有内置的字符串类型,而是在标准Java类库中提供了一个预定义类String,每个用双引号的括起来的字符串都是String类的一个实 ...

  3. Java的不定参数(eg:Object...)(转)

    第一个例子: public class VariArgs { public static void main(String[] args) { test(); test("aaa" ...

  4. foobar2000设置关闭按钮最小化到系统托盘

    1.设置托盘选项: 2.[File]->[Preferences]->[Advanced]->[Display]->[Default User Interface]->[ ...

  5. php 中函数获取可变参数的方法, 这个语法有点像 golang 语言中的

    原文呢:http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict Onl ...

  6. linux下查看网卡信息的命令

    rhel 内核版本号信息: [root@hvrhub ~]# uname -a Linux hvrhub 2.6.18-308.el5 #1 SMP Fri Jan 27 17:17:51 EST 2 ...

  7. 创建JDBC模板简化代码、JDBC应用的事务管理以及连接池的作用

    一.创建JDBC模板简化代码 一个简单的查询.要做这么一大堆事情,并且还要处理异常,我们不防来梳理一下: 1.获取connection  2.获取statement  3.获取resultset  4 ...

  8. 九度OJ #1437 To Fill or Not to Fil

    题目描写叙述: With highways available, driving a car from Hangzhou to any other city is easy. But since th ...

  9. 加载和执行 --《高性能JavaScript》

    1.起因: 每次遇到<script> 标签时,页面必须停下来等待代码下载并执行完,然后再继续处理其他部分. 2.减少JavaScript对性能的影响 1.将所有的JavaScript文件放 ...

  10. linux输入子系统(6)-input子系统介绍及结构图

    注:本系列转自: http://www.ourunix.org/post/290.html input子系统介绍         输入设备(如按键,键盘,触摸屏,鼠标,蜂鸣器等)是典型的字符设备,其一 ...