Codeforces Round #604 (Div. 2) B. Beautiful Numbers
链接:
https://codeforces.com/contest/1265/problem/B
题意:
You are given a permutation p=[p1,p2,…,pn] of integers from 1 to n. Let's call the number m (1≤m≤n) beautiful, if there exists two indices l,r (1≤l≤r≤n), such that the numbers [pl,pl+1,…,pr] is a permutation of numbers 1,2,…,m.
For example, let p=[4,5,1,3,2,6]. In this case, the numbers 1,3,5,6 are beautiful and 2,4 are not. It is because:
if l=3 and r=3 we will have a permutation [1] for m=1;
if l=3 and r=5 we will have a permutation [1,3,2] for m=3;
if l=1 and r=5 we will have a permutation [4,5,1,3,2] for m=5;
if l=1 and r=6 we will have a permutation [4,5,1,3,2,6] for m=6;
it is impossible to take some l and r, such that [pl,pl+1,…,pr] is a permutation of numbers 1,2,…,m for m=2 and for m=4.
You are given a permutation p=[p1,p2,…,pn]. For all m (1≤m≤n) determine if it is a beautiful number or not.
思路:
记录每个值的位置,从1开始让最小的区间包围1-i,如果区间长度正好等于i就说明是一个i的排列。
代码:
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10;
int p[MAXN];
int n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while(t--)
{
cin >> n;
int a;
for (int i = 1;i <= n;i++)
cin >> a, p[a] = i;
int l, r;
l = r = p[1];
cout << 1;
for (int i = 2;i <= n;i++)
{
l = min(l, p[i]);
r = max(r, p[i]);
if (r-l+1 == i)
cout << 1;
else
cout << 0;
}
cout << endl;
}
return 0;
}
Codeforces Round #604 (Div. 2) B. Beautiful Numbers的更多相关文章
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)
题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest
链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors
链接: https://codeforces.com/contest/1265/problem/E 题意: Creatnx has n mirrors, numbered from 1 to n. E ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)
题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)
题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...
随机推荐
- wmi的作用
WMI是Windows 2K/XP管理系统的核心,对于其他的Win32操作系统,WMI是一个有用的插件. WMI的作用是: ①通过它可以访问.配置.管理和监视几乎所有的Windows资源,比如用户可以 ...
- 如何申请百度地图用户Key
打开网页http://lbsyun.baidu.com/,进入百度地图开发平台. 单击[登录],登录百度账号.如果您还没有百度账号,单击箭头处[立即注册]注册百度账号. 登录完成后,单击右上角箭头处[ ...
- 使用ImagesPipeline时候报错为:ModuleNotFoundError: No module named 'scrapy.contrib'
刚开始我是这样写的: 报错为: 哈哈,经过查阅资料,其实他是存在的,接下来修改如下: 经过运行结果如下: 问题解决,哈哈哈,搞定!!!!!!!!!!!!
- 11 IO流(八)——装饰器设计模式,Filter装饰流
声明:本文部分图片及内容引用自:https://www.cnblogs.com/qiumingcheng/p/5219631.html java装饰器设计模式 举一个形象的例子,人可以说话,而扩音器可 ...
- Python3实现一个简单的tcp客户端,用于测试服务端端口开放情况
需要Python的socket模块儿,windows使用netstat -an查看端口状态,Linux使用netstat -tunlp查看端口状态. # client 客户端 # TCP必须建立连接 ...
- Scratch编程:贪吃鱼(十一)
“ 上节课的内容全部掌握了吗?反复练习了没有,编程最好的学习方法就是练习.练习.再练习.一定要记得多动手.多动脑筋哦~~” 01 — 游戏介绍 这是一个小游戏,通过键盘的方向键控制着大鲨鱼追着吃掉海星 ...
- tidb测试环境搭建
tidb ansible 部署方式环境检查过于严格,测试环境往往达不到标准,需调整一些参数才能部署成功. 基于tidb2.0版本需要调整的参数 [tidb@ansible01 tidb-ansible ...
- Jekyll自动检测代码更新
Jekyll自动检测代码更新 jekyll是一个静态博客生成软件, 我们把代码放在一个仓库里, 只要远程代码更新, 我们就从把它拉到自己的服务器, 然后重新启动jekyll. cd /root/blo ...
- SpringBoot打成jar包后无法读取resources资源文件
在项目中做了一个支付功能, 需要引入第三方渠道的配置文件config.xml用来初始化文件证书, 将配置文件 config.xml 放到 resources 资源目录下. 本地开发环境下能正常读取该文 ...
- 【OO学习】OO第三单元作业总结
[OO学习]OO第三单元作业总结 第三单元,我们学习了JML语言,用来进行形式化设计.本单元包括三次作业,通过给定的JML来实行了一个对路径的管理系统,最后完成了一个地铁系统,来管理不同的线路,求得关 ...