【题目链接】

点击打开链接

【算法】

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

在判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. Executors

    提供了工厂方法: Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, Thread ...

  2. codevs——2693 上学路线(施工)

    2693 上学路线(施工)  时间限制: 2 s  空间限制: 16000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 问题描述 你所在的城市街道好像一个 ...

  3. All you need to know about SYN floods

    http://blog.dubbelboer.com/ Date: 09 Apr 2012Author: Erik Dubbelboer SYN cookies So one day I notice ...

  4. Ubuntu Desktop 常用软件

    IDE: eclipse ***: firefox,登陆账号可以同步书签,我用了全球账号. firefox插件:FireGestures(手势), NoSquint(全局缩放),Url to QRco ...

  5. 使用azure send grid发送email

    1. create a send grid account 2. remember the username/password of the send grid account watermark/2 ...

  6. SAP 锁对象 基本概念与基本操作 SE11

      一.SAP为什么要设置锁:     1,保持数据的一致性     假设几个用户要訪问相同的资源,须要找到一种同步訪问的方法去保持数据的一致性.比方说,在航班预订系统中,须要检查还有没有空座位,当检 ...

  7. apk解包——修改后缀为zip

    将apk修改后缀为zip后,可直接解包查看资源文件

  8. java开始到熟悉70-71

    本次内容:file类 package array; /** * file类 */ import java.io.File; import java.io.IOException; public cla ...

  9. windows核心编程之进程间共享数据

    有时候我们会遇到window进程间共享数据的需求,例如说我想知道系统当前有多少某个进程的实例. 我们能够在程序中定义一个全局变量.初始化为0.每当程序启动后就加1.当然我们我们能够借助第三方介质来储存 ...

  10. Apache Qpid消息通讯模型和消息地址简介

    Broker知识准备 Broker内置两种节点类型:一种是 queue,一种是 topic. 1.  queue 节点能够缓存消息,直到被读取走为止.queue节点满足两个重要的 PTP 通信的特征, ...