CF#637 C. Nastya and Strange Generator
C. Nastya and Strange Generator
题意
有一个随机全排列生成器,给出你一个全排列,让判断是否可以通过这个生成器产生。
生成器工作方式:
第i步为数字i寻找位置pos。
首先pos是一个空位置,定义每个空位置的价值为左边连续有数字的位置数,会为数字i在价值最大的一个或者多个位置中选择一个位置。

比如上图,第三个位置的值是2,第4个位置的值是0,这时4就选择了第3个位置。
思路
写一下就会发现,这个生成器生成的全排列是有规律的。
n的全排列
x+y+1 x+y+2.....n x+1 x+2... x+y 1 2 3 4.......x
可以知道如果当前位小于后一位,一定是小1。如果有不是小1的,就说明不能通过生成器生成
代码
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int arr[N],vis[N];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&arr[i]);
int flag=0;
for(int i=n;i>1;i--)
{
if(arr[i]>arr[i-1])
{
if(arr[i]-arr[i-1]!=1)
{
flag=1;
break;
}
}
}
if(flag) printf("No\n");
else printf("Yes\n");
}
return 0;
}
CF#637 C. Nastya and Strange Generator的更多相关文章
- CF#637 D. Nastya and Scoreboard DP
D. Nastya and Scoreboard 题意 一块电子屏幕上有n个数字. 每个数字是通过这样7个线段显示的,现在你不小心打坏了k个线段,给出打坏之后的n个数字的显示方式,问之前的屏幕表示的最 ...
- Codeforces Round #637 (Div. 2) 题解
A. Nastya and Rice 网址:https://codeforces.com/contest/1341/problem/A Nastya just made a huge mistake ...
- Codeforces Round #637 (Div. 2)
比赛链接:https://codeforces.com/contest/1341 A - Nastya and Rice 题意 有 n 堆米,每堆质量在 [a-b,a+b] 之间,这些米的总质量是否可 ...
- MyBatis-Plus学习笔记(2):代码生成器
AutoGenerator 是 MyBatis-Plus 的代码生成器,通过 AutoGenerator 可以快速生成 Entity.Mapper.Mapper XML.Service.Control ...
- CF 305A——Strange Addition——————【暴力加技巧】
A. Strange Addition time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【CF edu 30 C. Strange Game On Matrix】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standa ...
- CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)
Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month ...
- CF 1136B Nastya Is Playing Computer Games
题目链接:codeforces.com/problemset/problem/1136/B 题目分析 首先,读完题目,看了是个B题,嗯嗯...... 果断找规律,然后交了一波,居然过了!!! 代码区 ...
- CF 1136C Nastya Is Transposing Matrices
题目链接:http://codeforces.com/problemset/problem/1136/C 题目分析 看了题目之后,第一想法:任意位置都可以倒置,要是枚举,铁定的超时.所以需要探索规律. ...
随机推荐
- vs 基础
1 写入 读取: 1) 写入:Console.Write("hello china") 光标紧跟 ...
- Tensorflow 模型线上部署
获取源码,请移步笔者的github: tensorflow-serving-tutorial 由于python的灵活性和完备的生态库,使得其成为实现.验证ML算法的不二之选.但是工业界要将模型部署到生 ...
- MVC-第一个简单的程序
来源于:https://www.cnblogs.com/miro/p/4030622.html 从空白开始,建立一个基本框架详细步骤 1,新建项目 NOTE:模板要选Empty,如果直接选MVC会产生 ...
- MySQL主从复制,主主复制,半同步复制
实验环境: 系统:CentOS Linux release 7.4.1708 (Core) mariadb:mariadb-server-5.5.56-2.el7.x86_64 node1:172.1 ...
- Async,Await 深入源码解析
1.同步与异步 假设存在 IO事件A:请求网络资源 (完成耗时5s) IO事件B:查询数据库 (完成耗时5s) 情况一:线程1工人在发起A请求后,一直阻塞等待,在A响应返回结果后再接着处理事件B,那总 ...
- 0day笔记(1)PE文件格式与虚拟文件内存的映射
PE文件格式 PE 文件格式把可执行文件分成若干个数据节(section),不同的资源被存放在不同的节中. 一个典型的 PE 文件中包含的节如下: .text 存放着二进制的机器代码 .data 初始 ...
- SpringBoot中使用Fastjson/Jackson对JSON序列化格式化输出的若干问题
来源 :https://my.oschina.net/Adven/blog/3036567 使用springboot-web编写rest接口,接口需要返回json数据,目前国内比较常用的fastjso ...
- Visual Studio Code mac OS 安装 中文简体语言包
先下载中文简体语言包 官网 https://marketplace.visualstudio.com/search?target=VSCode&category=Language%20Pack ...
- Eclipse Mac OS 安装中文简体语言包
打开Eclipse软件,在导航Eclipse下拉菜单中点开 About Eclipse 查看版本 我的是 Eclipse IDE for Enterprise Java Developers. Ver ...
- 《Microduino实战》——2.3 Microduino STM32核心系列
本节书摘来自华章出版社<Microduino实战>一 书中的第2章,第2.3节,作者:姚琪 杨立斌,更多章节内容可以访问云栖社区"华章计算机"公众号查看. 2.3 Mi ...