Luogu3952 NOIP2017时间复杂度
搞一个栈模拟即可。对比一下和一年前考场上的代码233
//2018.11.8
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 110
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<''||c>'')) c=getchar();return c;}
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
int getlim()
{
char c=getc();
if (c=='n') return ;
else
{
int l=c^,c=getchar();
if (c>=''&&c<='') l=l*+(c^);
return l;
}
}
int T,top;
bool isenter[N],isconst[N],isappear[];
char var[N];
int main()
{
T=read();
while (T--)
{
memset(isappear,,sizeof(isappear));top=;
int n=read();getc();
char c=getc();int p;
if (c=='') p=;else p=read();
bool iserr=;int cnt=,ans=,isout=;
while (n--)
{
c=getc();
if (c=='F')
{
char v=getc();
if (isappear[v]) iserr=;
int l=getlim(),r=getlim();
if (!iserr)
{
var[++top]=v;isappear[v]=;
isconst[top]=r-l<=;
isenter[top]=r>=l;
if (!isout) ans=max(ans,cnt+=isconst[top]^);
isout+=isenter[top]^;
}
}
else
{
if (top==) iserr=;
if (!iserr)
{
isout-=isenter[top]^;
if (!isout) cnt-=isconst[top]^;
isappear[var[top]]=;
top--;
}
}
}
if (top!=) iserr=;
if (iserr) cout<<"ERR"<<endl;
else if (ans==p) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return ;
}
//2017.11.11
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int t,n,w,top;
bool flag=,a[],ifn[],ifcmp[];
char stk[];
int main()
{
cin>>t;
while (t>)
{
t--;
cin>>n;
char c=getchar();
while ((c<''||c>'')&&(c!='n')) c=getchar();
//cout<<c<<endl;
if (c=='') w=;
else
{
c=getchar();
cin>>w;
}
//cout<<w<<endl;
c=getchar();
top=;
memset(a,,sizeof(a));
memset(ifcmp,,sizeof(ifcmp));
flag=;
int o=,MAX=,iflr=;
for (int i=;i<=n;i++)
{
c=getchar();while (c!='E'&&c!='F') c=getchar();
if (c=='E')
{
if (top<=) flag=;
else
{
a[stk[top]]=;
if (ifn[top]) o--;
if (ifcmp[top]) iflr--;
top--;
}
}
else
{
char x;int l,r;
cin>>x;char tmp=x;
if (a[x]) flag=;
else
{
a[x]=;
cin>>x;
if (x=='n') l=;
else
{
l=x-;
x=getchar();
if (x>=''&&x<='') l=l*+x-;
}
cin>>x;
if (x=='n') r=;
else
{
r=x-;
x=getchar();
if (x>=''&&x<='') r=r*+x-;
}
if (l>r)
{
top++;
stk[top]=tmp;
ifn[top]=;
ifcmp[top]=;
iflr++;
}
else if(l<&&r<||l==r)
{
top++;
stk[top]=tmp;
ifn[top]=;
ifcmp[top]=;
}
else
{
top++;
stk[top]=tmp;
if (iflr) ifn[top]=;
else
{
ifn[top]=;
o++;
if (o>MAX) MAX=o;
}
ifcmp[top]=;
}
}
}
}
if (top>) flag=;
if (!flag) cout<<"ERR"<<endl;
else
{
if (MAX==w) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
return ;
}
Luogu3952 NOIP2017时间复杂度的更多相关文章
- 【比赛】NOIP2017 时间复杂度
恶心的模拟题,考场上犯了一堆错误,多组数据清空没清完.数组开小...民间都是50分,结果CCF90.. 考完后随便改改就过了,还好只少了10分,如果真的是50,我估计会疯掉. 因为考场的时候没写好,所 ...
- [Luogu 3952] NOIP2017 时间复杂度
[Luogu 3952] NOIP2017 时间复杂度 一年的时间说长不长,说短,也不短. 一年之内无数次觉得难得可怕的题目,原来也就模拟这么回事儿. #include <cstdio> ...
- P3952 NOIP2017 时间复杂度
写了两三个小时,麻烦倒是不麻烦,要考虑清楚,想全了 只过了样例提交是不是傻,要自己造数据 数据不大可以用STL 建议自己刚一下,不看代码 #include <iostream> #incl ...
- luoguP3952 [NOIP2017]时间复杂度 模拟
原本只是想看下多久能码完时间复杂度 然后在30min内就码完了,然后一A了???? 首先,这题完全可以离线做 我们先把所有的操作读完,判断合不合法之后,再去判断和标准答案的关系 具体而言 把所有的操作 ...
- [NOIP2017]时间复杂度
题目描述 小明正在学习一种新的编程语言 A++,刚学会循环语句的他激动地写了好多程序并 给出了他自己算出的时间复杂度,可他的编程老师实在不想一个一个检查小明的程序, 于是你的机会来啦!下面请你编写程序 ...
- 【洛谷P3952】[NOIP2017]时间复杂度
时间复杂度 题目链接 对于 100%的数据:L≤100 . 很明显的模拟题 然而考试时还是爆炸了.. 调了一下午.. 蒟蒻表示不会离线操作.. 直接贴代码: #include<cstdio> ...
- NOIP2017 时间复杂度 大模拟
再写一道大模拟题. 由于是限时写的,相当于考场代码,乱的一批. 题目链接:P3952 时间复杂度 先记几个教训: 字符串形式的数字比较大小老老实实写函数,字典序都搞错几次了 栈空的时候不但pop()会 ...
- 【题解】NOIP2017时间复杂度
对大模拟抱有深深的恐惧……不过这次写好像还好?拿个栈维护一下循环的嵌套,然后重定义一下读入即可.记得去年在考场上面死活调不粗来,代码也奇丑无比……希望今年能好一点吧! #include <bit ...
- [NOIP2017]时间复杂度(模拟)
sscanf读入数字,getline(cin,string)读一整行,其余暴力模拟即可. #include<cstdio> #include<string> #include& ...
随机推荐
- php访问url(get和post请求)
get请求 /* * php访问url路径,get请求 */ function curl_file_get_contents($durl){ // header传送格式 $headers = arra ...
- (转)Updates were rejected because the tip of your current branch is behind
刚创建的github版本库,在push代码时出错: $ git push -u origin masterTo git@github.com:******/Demo.git ! [rejected] ...
- 某CTF收集的Mysql爆表、爆字段语句
Mysql特性 获取数据库名未知函数可爆数据库名 FUNCTION youcanneverfindme17.a does not exist 获取表名and linestring(pro_id) ...
- node 动态页面渲染
代码: 'use strict' const express = require('express'); const consoldiate = require('consolidate'); con ...
- System.Speech使用
使用微软语音库 使用微软语音库可以很快速的制作一个小应用,比如一个唐诗的朗诵工具.本示例也是使用微软语音库,制作了一个唐诗宋词朗诵的应用,仅供加深学习印象 首先是要引入System.Speech库 然 ...
- (数据科学学习手札18)二次判别分析的原理简介&Python与R实现
上一篇我们介绍了Fisher线性判别分析的原理及实现,而在判别分析中还有一个很重要的分支叫做二次判别,本文就对二次判别进行介绍: 二次判别属于距离判别法中的内容,以两总体距离判别法为例,对总体G1,, ...
- (数据科学学习手札12)K-means聚类实战(基于R)
上一篇我们详细介绍了普通的K-means聚类法在Python和R中各自的实现方法,本篇便以实际工作中遇到的数据集为例进行实战说明. 数据说明: 本次实战样本数据集来自浪潮集团提供的美团的商家信息,因涉 ...
- [Cracking the Coding Interview] 4.3 List of Depths
Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth. ...
- python2.7练习小例子(二十五)
25):题目:有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁.问第4个人岁数,他说比第3个人大2岁.问第三个人,又说比第2人大两岁.问第2个人,说比第一个人大两岁.最后问第一个人,他 ...
- VGA 时序标准
VGA 显示器扫描方式从屏幕左上角一点开始,从左像右逐点扫描,每扫描完一行,电子束回到屏幕的左边下一行的起始位置,在这期间,CRT 对电子束进行消隐,每行结束时,用行同步信号进行同步:当扫描完所有的行 ...