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& ...
随机推荐
- NFS网络文件系统详解
第1章 NFS基本概述 1.1 什么是nfs NFS是Network File System的缩写及网络文件系统. 主要功能是通过局域网络让不同的主机系统之间可以共享文件或目录. NFS系统和Wind ...
- linux链路聚合
配置聚合连接(网卡绑定,链路聚合): eth0 ================>>虚拟网卡team eth1 配置聚合连接 [root@Centos7-Server ~]# nmcli ...
- flex布局设置min-width
在一个flex布局中,对于一个设置了flex属性设置为1的div容器,再对其设置min-width:0,保证内容不超出外层容器
- 【mysql学习-1】
part-1: #use mysql;/*show tables;select * from user;use mysql;show databases;#create database db1; # ...
- es6几个新增语法的使用----数组
//数组的累加方法 let arr=[1,2,3]; let sum=arr.reduce((prev,cur)=>{ return prev+cur; }) console.log(sum)/ ...
- ruby net/http模块使用
ruby中的NET::HTTP:这里暂时先列出几个固定用法: 其中一,二不支持请求头设置(header取ruby默认值),只能用于基本的请求,不支持持久连接,如果您执行许多HTTP请求,则不推荐它们: ...
- ubuntu下安装LAMP环境遇到的一些小问题
0x00 今天在服务器上重新弄了一下lamp环境 安装的过程中遇到了不少小问题 记录一下解决的方案吧 服务器安装的是ubuntu 16.04.1 0x01 首先在用 apt-get install 安 ...
- 1977: [BeiJing2010组队]次小生成树 Tree
1977: [BeiJing2010组队]次小生成树 Tree https://lydsy.com/JudgeOnline/problem.php?id=1977 题意: 求严格次小生成树,即边权和不 ...
- linux命令大全(转载)
在搭建openstack时遇到问题,导致上网查询相关信息.找到一篇不错的文章,希望对大家有用.下附地址: http://blog.csdn.net/junbujianwpl/article/detai ...
- 【数据库】 SQL 常用语句
[数据库] SQL 常用语句 1.批量导入 INSERT INTO Table2(field1,field2,...) SELECT value1,value2,... FROMTable1 要求目标 ...