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$ 枚铜牌 ...
随机推荐
- js继承的几种方法理解和代码演示
1.属性继承 :call .apply:不建议使用浪费内存. function Person(name,age,sex){ this.name = name; this.age = age; this ...
- Java开发笔记(一百三十四)Swing的基本对话框
桌面程序在运行过程中,时常需要在主界面之上弹出小窗,把某种消息告知用户,以便用户及时知晓并对症处理.这类小窗口通常称作对话框,依据消息交互的过程,可将对话框分为三类:消息对话框.确认对话框.输入对话框 ...
- logrus 剖析之 formatter
使用 logrus 通过 formatter 来定义输出日志的格式,具体例子如下: package main import ( log "github.com/Sirupsen/logrus ...
- SpirngBoot--错误消息的定制
在SpringBoot中发生了4xx 5xx之类的错误,SpringBoot默认会发一个/error的请求,该请求由BasicErrorController处理,即在SpringBoot中错误处理也是 ...
- python --- 字符编码学习小结(二)
距离上一篇的python --- 字符编码学习小结(一)已经过去2年了,2年的时间里,确实也遇到了各种各样的字符编码问题,也能解决,但是每次都是把所有的方法都试一遍,然后终于正常.这种方法显然是不科学 ...
- .net core web API使用Identity Server4 身份验证
一.新建一个.net core web项目作为Identity server 4验证服务. 选择更改身份验证,然后再弹出的对话框里面选择个人用户账户. nuget 安装Identity server相 ...
- js 简单的滑动2
js 简单的滑动教程(二) 作者:Lellansin 转载请标明出处,谢谢 现在我们让滑动多一个功能,三张图.点击左边向左滑动,点右向右滑,碰到临界值的时候可以循环滑动 原理也很将简单,用posi ...
- SharePoint中用Power shell命令修改文档的创建时间
第一步:pnp组件连接到SharePointConnect-PnpOnline -url 网站地址 第二步:查出文档库及文档库下所有的文件 Get-PnPListItem -List 文档库名称 第三 ...
- ping pathping tcping psping tracert
ping pathping tcping psping tracert 1.Ping命令. 当您的机器不能访问Internet,首先确认是否是本地局域网的故障.假定局域网的代理服务器IP地址为202. ...
- 一个 Vim 重度用户总结的 vim 超全指南
我本人是 Vim 的重度使用者,就因为喜欢上这种双手不离键盘就可以操控一切的feel,Vim 可以让我对文本的操作更加精准.高效. 对于未使用过 Vim 的朋友来说,可能还无法体会到这种感觉.由于使用 ...