poj1363 Rails Central Europe 1997
P.S.:
输出换行
三个方法

1.直接按照要求做
根据给的数,需要push,pop哪些数据,具有唯一性
数最多进栈一次,出栈一次
O(n)
Source Code
Problem: User: congmingyige
Memory: 728K Time: 63MS
Language: G++ Result: Accepted Source Code #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long const double eps=1e-;
const ll inf=1e9;
const ll mod=1e9+;
const int maxn=1e5+; int a[maxn];
int st[maxn]; int main()
{
int n,i,j,g;
bool line=;
while ()
{
scanf("%d",&n);
if (n==)
break; if (!line)
line=;
else
printf("\n"); g=;
while ()
{
scanf("%d",&a[]);
if (a[]==)
break;
for (i=;i<=n;i++)
scanf("%d",&a[i]); j=;
for (i=;i<=n;i++)
{
while (j<a[i])
st[++g]=++j;
if (st[g]==a[i])
g--;
else
break;
} if (i==n+)
printf("Yes\n");
else
printf("No\n");
}
}
return ;
}
/*
6
1 3 2 4 6 5
1 4 3 5 2 6
1 3 6 5 2 4
5 4 3 2 1 6
5 3 2 1 6 4
1 3 5 4 6 2
1 3 6 2 5 4 4
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1 2 3 1 4
*/
2.
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long const double eps=1e-;
const ll inf=1e9;
const ll mod=1e9+;
const int maxn=1e5+; int a[maxn];
bool vis[maxn]; int main()
{
int n,i,j;
bool line=;
while ()
{
scanf("%d",&n);
if (n==)
break; if (!line)
line=;
else
printf("\n"); while ()
{
scanf("%d",&a[]);
if (a[]==)
break;
for (i=;i<=n;i++)
scanf("%d",&a[i]); memset(vis,,sizeof(vis));
j=;
for (i=;i<=n;i++)
{
if (j>a[i])
break;
else if (j<=a[i])
j=a[i]-; vis[a[i]]=;
while (vis[j])
j--;
} if (i==n+)
printf("Yes\n");
else
printf("No\n");
}
}
return ;
}
/*
6
1 3 2 4 6 5
1 4 3 5 2 6
1 3 6 5 2 4
5 4 3 2 1 6
5 3 2 1 6 4
1 3 5 4 6 2
1 3 6 2 5 4 8
1 3 6 8 7 5 4 2 4
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1 2 3 1 4
*/
previous数组
一个数跳出,使用previous数组,这个数不再被使用
O(n)
1 3 2 6 5 4 9 8 7
则
previous[4] 0
previous[6] 6->5->4->0 0
previous[7] 7->6->0
极限数据
1 2 3 4 5 6 7 8 9
按照上述方法O(n^2)
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long const double eps=1e-;
const ll inf=1e9;
const ll mod=1e9+;
const int maxn=1e5+; int a[maxn],pre[maxn];
bool vis[maxn]; int main()
{
int n,i,j,k;
bool line=;
while ()
{
scanf("%d",&n);
if (n==)
break; if (!line)
line=;
else
printf("\n"); while ()
{
scanf("%d",&a[]);
if (a[]==)
break;
for (i=;i<=n;i++)
scanf("%d",&a[i]); memset(vis,,sizeof(vis));
j=;
for (i=;i<=n;i++)
{
if (j>a[i])
break;
else if (j<=a[i])
j=a[i]-,k=j; vis[a[i]]=;
while (vis[j])
{
if (pre[j])
j=pre[j];
else
j--;
}
if (j!=k)
pre[k]=j;
} if (i==n+)
printf("Yes\n");
else
printf("No\n");
}
}
return ;
}
/*
6
1 3 2 4 6 5
1 4 3 5 2 6
1 3 6 5 2 4
5 4 3 2 1 6
5 3 2 1 6 4
1 3 5 4 6 2
1 3 6 2 5 4 8
1 3 6 8 7 5 4 2 4
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1 2 3 1 4
*/
poj1363 Rails Central Europe 1997的更多相关文章
- Sticks(Central Europe 1995) (DFS)
Sticks(Central Europe 1995) Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d &am ...
- ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...
- Central Europe Regional Contest 2012 Problem I: The Dragon and the Knights
一个简单的题: 感觉像计算几何,其实并用不到什么计算几何的知识: 方法: 首先对每条边判断一下,看他们能够把平面分成多少份: 然后用边来对点划分集合,首先初始化为一个集合: 最后如果点的集合等于平面的 ...
- Central Europe Regional Contest 2012 Problem c: Chemist’s vows
字符串处理的题目: 学习了一下string类的一些用法: 这个代码花的时间很长,其实可以更加优化: 代码: #include<iostream> #include<string> ...
- Central Europe Regional Contest 2012 Problem J: Conservation
题目不难,感觉像是一个拓扑排序,要用双端队列来维护: 要注意细节,不然WA到死 = =! #include<cstdio> #include<cstring> #includ ...
- Central Europe Regional Contest 2012 Problem H: Darts
http://acm.hunnu.edu.cn/online/problem_pdf/CERC2012/H.pdf HUNNU11377 题意:飞镖环有十个环,没个环从外到里对应一个得分1~10,每个 ...
- 2017-2018 ACM-ICPC, Central Europe Regional Contest (CERC 17)
A. Assignment Algorithm 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string ...
- XV Open Cup named after E.V. Pankratiev. GP of Central Europe (AMPPZ-2014)--J.Cave
给你一棵树,现在有m个专家,每个专家计划从$a_i$走到$b_i$, 经过的距离不超过$d_i$,现在让你找一个点,使得所有专家的路途都能经过这个点 令$S_i$表示满足第i个专家的所有点,先检查1可 ...
- XV Open Cup named after E.V. Pankratiev. GP of Central Europe (AMPPZ-2014)--B.Petrol
多源最短路+并查集 #include <bits/stdc++.h> using namespace std; #define rep(i, j, k) for (int i = int( ...
随机推荐
- <软件测试>软件测试
1.软件测试基础 软件测试工程师:查找错误和缺陷,然后要求开发人员进行修改,保证软件质量. 漏洞(360安全漏洞):硬件,软件,协议的具体实现或系统安全策略存在缺陷,从而可以使攻击者在未授权的情况下破 ...
- 从零开始学Jqueue
http://www.cnblogs.com/zhangziqiu/archive/2009/04/30/jQuery-Learn-1.html
- 随笔记录 shell脚本相关内容 2019-8-26
字符串截取: 假设变量为var=http://www.hao.com/123.htm1. # 号截取,删除左边字符,保留右边字符.echo ${var#*//}其中 var 是变量名,# 号是运算符, ...
- VS2017 打包(详细)
1.安装打包插件:Microsoft Visual Studio 2017安装程序项目 2.联机查找下面的组件,然后安装,重启VS,进行插件安装 3.新建安装项目,另外,有些人可能会想这么多安装类 ...
- 改变this 指向的3种方法
1.在函数内部声明一个that,然后将this赋值给that, var that=this; 最后用that 代替this使用 <!DOCTYPE html> <html lang= ...
- GitHub不能访问问题
在C:\Windows\System32\drivers\etc文件夹下HOSTS里面最后添加: 192.30.253.112 github.com 192.30.253.113 github.com ...
- 3年A班,从现在起大家都是人质-观后感
花了2天时间观看了由小室直子.铃木勇马.水野格导演,武藤将吾编剧的3年A班日剧. 这部剧我觉得很擅长用对比的手法,将一个受欢迎的老师人前人后强烈对比,一群外表成熟,内心却始终还是孩子气的学生对比,也将 ...
- 8-26接口压力测试-3Jmeter-Java请求
1.新建maven工程 2.导入依赖,并使用shade将所需的依赖打入jar包 <?xml version="1.0" encoding="UTF-8"? ...
- 进程、线程、协程、CPU
进程.线程.CPU 进程是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础.或者说进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动,进 ...
- Python 数据结构_队列
目录 目录 队列 队列 Queue 队列是一种先进先出(FIFO)的数据类型, 新的元素通过 入队 的方式添加进 Queue 的末尾, 出队 就是从 Queue 的头部删除元素. 用列表来做 Queu ...