题目链接
【题解】洛谷P3952[NOIP2017]时间复杂度 模拟
【题解】洛谷P3952[NOIP2017]时间复杂度 模拟
【题解】洛谷P3952[NOIP2017]时间复杂度 模拟
【题解】洛谷P3952[NOIP2017]时间复杂度 模拟


星际玩家不需要注意大小写……我提交七八遍没看出来自己大小写错了
大佬题解写得贼简洁,一看就是神仙,赶紧学习了

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int t,len,F,e,k,maxn,g[110],h,l[110],n,f[110];
string a,b;
int main()
{
	//freopen("in.txt","r",stdin);
    cin>>t;
    while(t--)
    {
    	len=0,F=0,e=0,k=0,maxn=0,memset(g,0,sizeof(g)),h=0,memset(l,0,sizeof(l)),n=0,memset(f,0,sizeof(f));
		do{
			a=b;cin>>b;
		}while(b[0]!='O');
		for(int i=0;i<a.length();i++)len=len*10+a[i]-'0';//长度 
	    for(int i=4;i<b.length()-1;i++)F=F*10+b[i]-'0';
		while(len>0)
		{
			cin>>a;len--;
			if(a[0]=='F')
			{
				cin>>a;e++;
				if(f[a[0]-96])e=-1;
				else f[a[0]-96]=1,g[e]=a[0]-96;//记一下e层循环的变量 
			    cin>>a>>b;//初始值和结束值 
			    if(a[0]!='n'&&b[0]=='n'&&k==0)h++,l[e]=1;
			    else if(((a.length()>b.length())||(a.length()==b.length()&&a>b)||(a[0]=='n'&&b[0]!='n'))&&k==0)k=1,n=e;//从n开始不能运行了 
			}
			else
			{
				maxn=max(maxn,h);f[g[e]]=0;
				if(l[e]==1)h--,l[e]=0;
				e--;
				if(n>0&&e<n)k=0,n=0;
			}
			if(e==-1){printf("ERR\n");len=-1;}
		}
		if(e>0)printf("ERR\n");
		if(e==0&&maxn==F)printf("Yes\n");
		if(e==0&&maxn!=F)printf("No\n");
	}
	return 0;
}

总结

能把大模拟写这么简介,也是很考技术的。好好学学。

相关文章: