BZOJ3403:[USACO2009OPEN]Cow Line
2024-09-04 18:03:18
浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html
题目传送门:https://lydsy.com/JudgeOnline/problem.php?id=3403
直接双端队列模拟即可。
时间复杂度:\(O(S)\)
空间复杂度:\(O(S)\)
代码如下:
#include <cstdio>
using namespace std;
const int maxn=1e5+5;
char s1[5],s2[5];
int list[maxn<<1];
int n,head,tail,cnt;
int read() {
int x=0,f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
}
int main() {
n=read();
head=tail=maxn;
while(n--) {
scanf("%s%s",s1+1,s2+1);
if(s1[1]=='A') {
if(s2[1]=='L')list[--head]=++cnt;
else list[tail++]=++cnt;
}
else {
int k=read();
if(s2[1]=='L')while(k--)head++;
else while(k--)tail--;
}
}
for(int i=head;i<tail;i++)
printf("%d\n",list[i]);
return 0;
}
最新文章
- WCF 定制自己的签名验证逻辑
- C# Process执行bat
- Windows server 2008R2部署服务批量安装Windows7教程
- 【PAT】1020. Tree Traversals (25)
- Python 第十二篇:HTML基础
- OTG驱动分析(二)
- win7电脑关机时间长怎么办
- iOS 本地视频和网络视频流播放
- 第二次作业:APP案例分析
- Spring cloud Greenwich Eureka
- vue-element-ui之弹窗重置
- 乐观锁vs悲观锁, 集群vs分布式 , 微服务, 幂等性
- 【hdu2000】ASCII码排序
- GFS浅析
- testng报告-extentsReports使用-klov
- C# 百度TTS,文本转语音,RestAPI之Get请求
- grid - 重复网格轨道
- vb.net連接Oracle数据库
- 第十七篇:IO复用之select实现
- ELK之收集tomcat访问日志