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. 快速列出大纲.提纲.归纳知识点 思维导图工具Xmind

    博客搬迁,给您带来的不便敬请谅解! http://www.suanliutudousi.com/2017/10/23/%E5%BF%AB%E9%80%9F%E5%88%97%E5%87%BA%E5%A ...

  2. 利用JFileChooser实现文件选择对话框

    简单的文件选择对话框: package mypackage;/** * 打开文件和存储文件 */import java.awt.BorderLayout;import java.awt.Contain ...

  3. ps--窗口配置

    移动工具设置 v 选择图层自动选择不勾 图层ctrl + 左键 视图设置智能参考线标尺 Ctrl+r 窗口设置 关闭 库 颜色 打开 信息 字符 图层 历史记录 信息 面板选项 鼠标单位 像素 rgb ...

  4. 前端之script标签注意事项

    在一对script 标签中一旦有错误,其后续的代码都不会执行 一对script标签有问题,不会影响其他script标签代码的执行 当一对script标签的作用是引入外部的js文件的时候,就不要在其内部 ...

  5. shell脚本中关于日期的操作

    一.计算指定日期的前一天的日期 date -d "yesterday 20150401 " +%Y%m%d 二.如果获取当前日期的前一天        date -d " ...

  6. 拦截器一Interceptor

    import org.springframework.web.servlet.HandlerInterceptor; 前言 拦截器,在AOP(Aspect-Oriented Programming)中 ...

  7. c++ exit() 函数

    函数用法 编辑 函数名: exit() 所在头文件:stdlib.h(如果是”VC6.0“的话头文件为:windows.h) 功 能: 关闭所有文件,终止正在执行的进程. exit(0)表示正常退出, ...

  8. Spring Data之Example<>

    简单CRUD之Example动态查询 简单介绍 (部分口水话,部分来自网络,代码永远自产) 使用过Spring全家桶的各位大佬应该都知道,Spring Data这个是Spring对持久层框架的封装,比 ...

  9. Go 动态类型声明

    Go 动态类型声明 package main import "fmt" func main() { var x float64 = 20.0 y := 42 fmt.Println ...

  10. (转)Android 创建与解析XML—— Dom4j方式 .

    转:http://blog.csdn.net/ithomer/article/details/7521605 1.Dom4j概述 dom4j is an easy to use, open sourc ...