UVA 514 Rails
来源:互联网 发布:上海大学云计算预约 编辑:程序博客网 时间:2024/06/09 20:38
栈模拟一下,看看输入的顺序能否由正整数序列得到。数组模拟栈或用stl都可以。
如果当前数字比栈顶大,就把之间没用过的都压进栈里,小就return 0,相等就弹栈。
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<vector>#include<string>#include<queue>#include<cmath>#include<set>///LOOP#define REP(i, n) for(int i = 0; i < n; i++)#define FF(i, a, b) for(int i = a; i < b; i++)#define FFF(i, a, b) for(int i = a; i <= b; i++)#define FD(i, a, b) for(int i = a - 1; i >= b; i--)#define FDD(i, a, b) for(int i = a; i >= b; i--)///INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)#define RFI(n) scanf("%lf", &n)#define RFII(n, m) scanf("%lf%lf", &n, &m)#define RFIII(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)#define RFIV(n, m, k, p) scanf("%lf%lf%lf%lf", &n, &m, &k, &p)#define RS(s) scanf("%s", s)///OUTPUT#define PN printf("\n")#define PI(n) printf("%d\n", n)#define PIS(n) printf("%d ", n)#define PS(s) printf("%s\n", s)#define PSS(s) printf("%s ", n)///OTHER#define PB(x) push_back(x)#define CLR(a, b) memset(a, b, sizeof(a))#define CPY(a, b) memcpy(a, b, sizeof(b))#define display(A, n, m) {REP(i, n){REP(j, m)PIS(A[i][j]);PN;}}using namespace std;typedef long long LL;typedef pair<int, int> P;const int MOD = 100000000;const int INFI = 1e9 * 2;const LL LINFI = 1e17;const double eps = 1e-6;const double pi = acos(-1.0);const int N = 1111;const int M = 22;const int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};int a[N], s[N], n, sp;bool vis[N];bool check(){ int m = 1; sp = 0; CLR(vis, 0); REP(i, n) { vis[a[i]] = 1; if(sp) { if(s[sp - 1] > a[i])return 0; else if(s[sp - 1] == a[i])sp--; } while(m < a[i]) { if(!vis[m])s[sp++] = m, vis[m] = 1; m++; } } return 1;}int main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); while(RI(n), n) { while(RI(a[0]), a[0]) { FF(i, 1, n)RI(a[i]); puts(check() ? "Yes" : "No"); } puts(""); } return 0;}
- Uva 514 Rails
- UVa 514 - Rails
- UVA 514 - Rails
- Uva Oj 514 - Rails
- uva 514 Rails
- UVA 514 Rails
- UVA 514 Rails
- Uva 514 Rails
- UVA 514 - Rails(模拟)
- UVA - 514 Rails
- UVa 514 Rails
- uva 514 - Rails(栈)
- UVa 514 Rails(栈)
- UVA 514 Rails
- UVa 514 - Rails
- UVA - 514 Rails
- UVa 514 - Rails
- Uva 514 Rails
- 03 Java语言流程控制
- Static 方法里面为何不能使用this
- NYOJ 464题 Cookies
- 操作系统的哲学
- Liskov替换原则--LSP
- UVA 514 Rails
- CWinApp中的InitInstance()
- C#使用LINQ to XML操作XML实例
- 单一职责原则--SRP
- 接口隔离原则--ISP
- unity3d SVN 版本冲突问题的解决
- 设计模式六大原则:接口隔离原则
- Main和WinMain函数执行前,系统进行的运行时裤的执行代码分析
- 小米公司编程题1(欢迎批评指正)