糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > codeforce C. Okabe and Boxes

codeforce C. Okabe and Boxes

时间:2024-05-16 11:37:26

相关推荐

codeforce C. Okabe and Boxes

题目传送门

这道题 每次删除一个点 那么这个点必然在栈里面 那么如果堆顶不是他 我们就需要一次操作使得堆合理 这时我们可以把他删除然后把他下面的点打个标记表示这下面的点以后想怎么排就怎么排以后都不需要操作到 这样就解决问题啦 233

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int M=3e5+7;int read(){int ans=0,f=1,c=getchar();while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}return ans*f;}int n,top,st[M],ans,cnt=1,f[M];int main(){char ch[15];int x;n=read();for(int i=1;i<=2*n;i++){scanf("%s",ch); if(ch[0]=='a') x=read(),st[++top]=x;else{if(!f[top]&&st[top]!=cnt) ans++,f[top]=1;if(f[top]) f[top]=0,f[top-1]=1;top--; cnt++;}}printf("%d\n",ans);return 0;}

View Code

如果觉得《codeforce C. Okabe and Boxes》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。