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( ...
随机推荐
- 高级Java必看的10本书
1.深入理解Java虚拟机:JVM高级特性与最佳实践 本书共分为五大部分,围绕内存管理.执行子系统.程序编译与优化.高效并发等核心主题对JVM进行了全面而深入的分析,深刻揭示了JVM的工作原理. 2. ...
- <思维导图>思维导图
- zabbix--添加用户
用户和用户组 概述 Zabbix 中的所有用户都通过 Web 前端去访问 Zabbix 应用程序.并为每个用户分配唯一的登陆名和密码. 所有用户的密码都被加密并储存于 Zabbix 数据库中.用户 ...
- 笔记:Python的浅复制和深复制
方法copy返回一个新字典,其包含的键-值对与原来的字典相同(这个方法执行的是浅复制,因为值本身是原件,而不是副本). >>> x = {"username": ...
- 笔记43 Spring Web Flow——订购披萨应用详解
一.项目的目录结构 二.订购流程总体设计 三.订购流程的详细设计 1.定义基本流程pizza-flow.xml <?xml version="1.0" encoding=&q ...
- PHP算法之有效的括号
给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合.左括号必须以正确的顺序闭合.注意空字符串可被认为是 ...
- Centos 14: problem making ssl connection
在执行 yum 命令时,会提示 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Could not g ...
- Linux service,挂载,定时任务等常用服务
一.防火墙 防火墙根据配置文件/etc/sysconfig/iptables 来控制本机的“出.入”网络访问行为 其对行为的配置策略有四个策 1. 基础必备技能 查看防火墙状态 s ...
- 程序‘vim’已包含在下列软件包中
解决方法: 输入:sudo apt-get install ctags 输入:sudo apt-get install vim 输入:sudo ./config.sh (亲测有效)输入:vim tes ...
- C# 与 C/C++ 网络传输字符串解决方案
{ 不管你的数据加没加密,只要有中文,请转16进制后再处理,把16进制再转为GB2312的byte再发送, 接收的话同样 c++ 发送时转16进制再发送,c#16进制转字符串后再转GB2312就可以了 ...