设为首页 加入收藏

TOP

HDU 4286 Data Handler (双端队列)(二)
2015-07-20 17:42:27 来源: 作者: 【 】 浏览:4
Tags:HDU 4286 Data Handler 双端 队列
(num[i]); REP(i,Lp,Rp) dqi.push_back(num[i]); REP(i,Rp+1,n ) rgt.push_back(num[i]); scanf("%d",&m); } void Reverse() { dir = 1-dir; } void Insert() { char op[20]; int x; scanf("%s%d",op,&x); if( (op[0]=='R' && dir) || (op[0] =='L' && !dir) ) { dqi.push_back(x); } else { dqi.push_front(x); } } void Delete() { char op[20]; scanf("%s",op); if( (op[0]=='R' && dir) || (op[0] =='L' && !dir) ) { dqi.pop_back(); } else { dqi.pop_front(); } } void MoveLeft() { char op[20]; scanf("%s",op); if( op[0]=='L' && dir ){ int x = lft.back(); lft.pop_back(); dqi.push_front(x); }else if( op[0]=='R' && !dir ){ int x = dqi.front(); dqi.pop_front(); rgt.push_front(x); } else if(op[0] == 'R' && dir){ int x = dqi.back(); dqi.pop_back(); rgt.push_front(x); } else { int x = lft.back(); lft.pop_back(); dqi.push_back(x); } } void MoveRight() { char op[20]; scanf("%s",op); if( (op[0]=='L' && dir)) { int x = dqi.front(); dqi.pop_front(); lft.push_back(x); } else if(op[0]=='R' && dir) { int x = rgt.front(); rgt.pop_front(); dqi.push_back(x); } else if(op[0]=='L' && !dir){ int x = dqi.back(); dqi.pop_back(); lft.push_back(x); }else{ int x = rgt.front(); rgt.pop_front(); dqi.push_front(x); } } void output() { bool flag = false; for(deque ::iterator it = lft.begin(); it != lft.end(); it++) { if(!flag) { printf("%d",*it); flag = true; } else { printf(" %d",*it); } } if(!dir) reverse(dqi.begin(),dqi.end()); for(deque ::iterator it = dqi.begin(); it != dqi.end(); it++) { if(!flag) { printf("%d",*it); flag = true; } else { printf(" %d",*it); } } for(deque ::iterator it = rgt.begin(); it != rgt.end(); it++) { if(!flag) { printf("%d",*it); flag = true; } else { printf(" %d",*it); } } puts(""); } void solve() { char cmd[20]; while(m--) { scanf("%s",cmd); if(cmd[0]=='R') Reverse(); else if(cmd[0]=='I') Insert(); else if(cmd[0] == 'D') Delete(); else if(cmd[0]=='M' && cmd[4]=='R') MoveRight(); else MoveLeft(); } output(); } int main(){ int ncase; cin >> ncase; while(ncase--) { init(); input(); solve(); } return 0; }


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 2486 Apple Tree 树形DP+分组.. 下一篇Surrounded Regions

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·MySQL 安装及连接-腾 (2025-12-25 06:20:28)
·MySQL的下载、安装、 (2025-12-25 06:20:26)
·MySQL 中文网:探索 (2025-12-25 06:20:23)
·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)