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.

一个序列,数x在第y个位置,第y个位置之后的小于x的数,必须是越往右越小。
即当前的最大数假设为z,则小于z的数必须是z-1,z-2,..,1。
 
时间上为O(n),但常数较大
 
 #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的更多相关文章

  1. Sticks(Central Europe 1995) (DFS)

    Sticks(Central Europe 1995) Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d &am ...

  2. 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 ...

  3. Central Europe Regional Contest 2012 Problem I: The Dragon and the Knights

    一个简单的题: 感觉像计算几何,其实并用不到什么计算几何的知识: 方法: 首先对每条边判断一下,看他们能够把平面分成多少份: 然后用边来对点划分集合,首先初始化为一个集合: 最后如果点的集合等于平面的 ...

  4. Central Europe Regional Contest 2012 Problem c: Chemist’s vows

    字符串处理的题目: 学习了一下string类的一些用法: 这个代码花的时间很长,其实可以更加优化: 代码: #include<iostream> #include<string> ...

  5. Central Europe Regional Contest 2012 Problem J: Conservation

    题目不难,感觉像是一个拓扑排序,要用双端队列来维护: 要注意细节,不然WA到死  = =! #include<cstdio> #include<cstring> #includ ...

  6. Central Europe Regional Contest 2012 Problem H: Darts

    http://acm.hunnu.edu.cn/online/problem_pdf/CERC2012/H.pdf HUNNU11377 题意:飞镖环有十个环,没个环从外到里对应一个得分1~10,每个 ...

  7. 2017-2018 ACM-ICPC, Central Europe Regional Contest (CERC 17)

    A. Assignment Algorithm 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string ...

  8. 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可 ...

  9. 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. 关于windows和linux系统更换JDK版本后,修改环境变量也无法生效的原因和解决办法

    今天遇到了一个问题: 我linux系统之前安装JDK12,今天将其改成了JDK1.8,并修改了环境变量,但是通过java -version命令显示的依旧是JDK12的版本. 这是因为,当使用安装版本的 ...

  2. 使用wireshark在windows平台下捕获HTTP协议数据包中的帐号密码信息

    1.打开wireshark软件,从Interface List中选择相应的网卡,例如我的PC机上是“本地连接”,然后选择”Start”启动抓包程序. 2.打开学校主页,输入账号和密码登录校内邮箱. 3 ...

  3. MYSQL分数排名

    编写一个 SQL 查询来实现分数排名.如果两个分数相同,则两个分数排名(Rank)相同.请注意,平分后的下一个名次应该是下一个连续的整数值.换句话说,名次之间不应该有“间隔”. +----+----- ...

  4. C/C++中的return和exit

    return:只是退出函数;  ~是关键字. exit:是退出进程; ~是函数名. 整理自:https://www.cnblogs.com/cxchanpin/p/6927025.html

  5. [转]C#对Excel报表进行操作(读写和基本操作)

    //1.添加引用-〉com-〉microsoft excel 11.0 //2.若出现错误:命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”(是缺少程序集引用吗 ...

  6. vscode编程nodejs初始安装

    nodejs官网 http://nodejs.cn/ 1.安装nodejs,记得安装时勾选配置路径 在cmd中输入node,进去node环境即为安装成功. 2.安装vscode,并安装插件node e ...

  7. 打开桌面上的图标就会弹出"打开些文件可能会对您的计算机有害"解决方案

    问题截图 方案步骤 运行 gpedit.msc 用户配置--管理模板--windows组件--附件管理器 找到中等危险文件类型抱含列表后右键-编辑 在指定中等风险扩展名中加入你文件的扩展名 应用, 确 ...

  8. DOM——属性操作

    属性操作 非表单元素的属性 href.title.id.src.className  var link = document.getElementById('link'); console.log(l ...

  9. Ruby 安装 – Unix

    Ruby 安装 - Unix 下面列出了在 Unix 机器上安装 Ruby 的步骤. 注意:在安装之前,请确保您有 root 权限. 下载最新版的 Ruby 压缩文件.请点击这里下载. 下载 Ruby ...

  10. Python 查看QQ状态

    import requests """ 该程序依赖于QQ的端口程序 返回数据:String,Y = 在线:N = 离线:E = QQ号码错误:A = 商业用户验证失败:V ...