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中有趣的String、StringBuffer与StringBuilder
String介绍 String类属于java.lang包中,String类是不可变类,任何对String的改变都会引发新的String对象的生成. 创建String的两种方式: 1.通过构造器创建:S ...
- pytest--两个fixture时,灵活运用
import pytest@pytest.fixture()def login_r(open_browser): print('登陆') @pytest.fixture()def open_brows ...
- android中的属性资源
属性资源可以很好的控制自定义View组件的外观行为. 属性资源放置在/res/values目录下,属性资源文件的根目录元素是<resources.../>,该元素包含如下两个子元素: at ...
- Spring案例1出纯注解开机
配置QueryRunner对象:注解说明 package cn.mepu.config; import org.apache.commons.dbutils.QueryRunner; import o ...
- position:relative/static/fixed/absolute定位的区别以及使用场景
absolute是相对于自己最近的父元素来定位的,relative是相对于自己来定位的 relative 不脱离文档流,absolute 脱离文档流.也就是说:relative 的元素尽管表面上看到它 ...
- html 通过input video canvas 打开摄像头 定制相机
在机缘巧合之下,了解到用HTML5和javascript调用摄像头来实现拍照功能,今天就把大致原理写下来.页面布局很简单,就是一个input标签,两个HTML5元素video.canvas和一个but ...
- php漂亮的分页类
<?php /* * PHP分页类 * @package Page * @Created 2013-03-27 * @Modify 2013-03-27 * ...
- EF批量添加
1.首先,打开工具——NuGet包管理器——管理解决方案的NoGet程序包——搜索Z.EntityFramework.Extensions 点击安装!!! codefirst定义一个实体,用EF的方法 ...
- 使用vue-cli 脚手架快速搭建单页面组件 -------webpack工具的介绍
在使用vue-cli时我们先了解一下什么是webpack. Webpack 是当下最热门的前端资源模块化管理和打包工具.它可以将许多松散的模块按照依赖和规则打包成符合生产环境部署的前端资源.还可以将按 ...
- jQuery - DOM相关
1. 操作文本 console.log($("#t1").html()); // 获取span元素中的内容, 包含html标签 $("#t1").html(&q ...