sgu271:Book Pile(reverse大法好)
来源:互联网 发布:弱矩阵 编辑:程序博客网 时间:2024/06/16 07:10
题目大意:
分析:
AC code:
#include <cstdio>#include <cmath>#include <cstdlib>#include <cstring>#include <cctype>#include <algorithm>#include <string>#include <sstream>#include <iostream>#include <map>#include <set>#include <list>#include <stack>#include <queue>#include <vector>#define pb push_back#define mp make_pairtypedef long long LL;typedef double DB;typedef long double LD;using namespace std;const int MAXN = 40009;const int MAXM = 100009;const int MAXK = 40009;const int SIGMA = 27;int n, m, k;int seq[MAXN+MAXM];int id[SIGMA][SIGMA][SIGMA], tot;char name[SIGMA*SIGMA*SIGMA][5];int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif char str[10] = "\0"; scanf("%d%d%d\n", &n, &m, &k); for(int i = n; i >= 1; --i) { gets(str); int need[5] = {0}; need[0] = str[0]-'A'+1; if(str[2] >= 'A' && str[2] <= 'Z') need[2] = str[2]-'A'+1; if(str[1] >= 'A' && str[1] <= 'Z') need[1] = str[1]-'A'+1; if(!id[need[0]][need[1]][need[2]]) { id[need[0]][need[1]][need[2]] = ++tot; strcpy(name[tot], str); } seq[i] = id[need[0]][need[1]][need[2]]; } bool tmp = false; while(m--) { char need[5] = "\0"; gets(str); if(str[0] == 'A') { if(tmp) { if(n < k) reverse(seq+1, seq+n+1); else reverse(seq+n-k+1, seq+n+1); } tmp = false; int t[5] = {0}; t[0] = str[4]-'A'+1; need[0] = str[4]; if(str[5] != ')') { t[1] = str[5]-'A'+1; need[1] = str[5]; if(str[6] != ')') { t[2] = str[6]-'A'+1; need[2] = str[6]; } } if(!id[t[0]][t[1]][t[2]]) { id[t[0]][t[1]][t[2]] = ++tot; strcpy(name[tot], need); } seq[++n] = id[t[0]][t[1]][t[2]]; } else tmp ^= true; } if(tmp) { if(n < k) reverse(seq+1, seq+n+1); else reverse(seq+n-k+1, seq+n+1); } for(int i = n; i >= 1; --i) puts(name[seq[i]]); #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0;}
0 0
- sgu271:Book Pile(reverse大法好)
- Book Pile sgu271
- SGU271. Book Pile(模拟)
- SGU 271 - Book Pile
- SGU - 271 Book Pile
- SGU 271 Book Pile 双端队列
- SGU 271Book Pile(模拟 deque+stack)
- SGU 271 Book Pile(deque)
- SGU 271 Book Pile(双端队列)
- 【SGU】271. Book Pile(双端队列模拟)
- clang 大法好
- DFS大法好
- UVA10499scanf大法好
- python大法好!
- rope大法好
- 盲打大法好
- 分块大法好
- Lombok大法好
- 数据库连接join
- 【C# WinForm】类似QQ靠近屏幕边缘缩放功能
- display:list-item和display:block区别
- POJ 1947树形DP
- Leetcode 226 Invert Binary Tree
- sgu271:Book Pile(reverse大法好)
- Missing Ranges
- mysql 运维角度浅谈:MySQL数据库优化
- George and Job
- Uniform Generator
- 使用ScrollView实现下拉刷新(一)
- CODE[VS] 1214 线段覆盖
- POJ 1155 树形DP
- 黑马程序员_面向对象2