题目描述

You are given an integer sequence x of length N. Determine if there exists an integer sequence a that satisfies all of the following conditions, and if it exists, construct an instance of a.

a is N2 in length, containing N copies of each of the integers 1, 2, …, N.
For each 1≤i≤N, the i-th occurrence of the integer i from the left in a is the xi-th element of a from the left.
Constraints
1≤N≤500
1≤xi≤N2
All xi are distinct.

输入

The input is given from Standard Input in the following format:

N
x1 x2 … xN

输出

If there does not exist an integer sequence a that satisfies all the conditions, print 'No'. If there does exist such an sequence a, print 'Yes'.

样例输入

3
1 5 9

样例输出

Yes
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int a[];
struct node
{
int num;
int x;
}s[];
bool cmp(node a,node b)
{
return a.x<b.x;
}
int main()
{
int i,j,n;
cin>>n;
for(i=;i<=n;i++){
cin>>s[i].x;
s[i].num=i;
}
sort(s+,s+n+,cmp);
int now=;
for(i=;i<=n;i++){
a[s[i].x]=s[i].num;
for(j=;j<s[i].num;j++){
while(a[now]) now++;
a[now]=s[i].num;
}
if(now>s[i].x) {cout<<"No"<<endl;return ;}
}
for(i=;i<=n;i++){
for(j=;j<=n-s[i].num;j++){
while(a[now]) now++;
if(now<s[i].x) {cout<<"No"<<endl;return ;}
a[now]=s[i].num;
}
}
cout<<"Yes"<<endl;
return ;
}

For each 1≤i≤N, the i-th occurrence of the integer i from the left in a is the xi-th element of a from the left.

就这句话。。。仔细读

第i个i在下标为xi的地方。嗯

这是贪心,先放上这些数字应在的位置

再从小到大把i弄上去

排除不可能的解

K-th K的更多相关文章

  1. 判断字符串是否包含字母‘k’或者‘K’

    判断字符串是否包含字母‘k’或者‘K’ public bool IsIncludeK(string temp) { temp = temp.ToLower(); if (temp.Contains(' ...

  2. 给定整数a1、a2、a3、...、an,判断是否可以从中选出若干个数,使得它们的和等于k(k任意给定,且满足-10^8 <= k <= 10^8)。

    给定整数a1.a2.a3.....an,判断是否可以从中选出若干个数,使得它们的和等于k(k任意给定,且满足-10^8 <= k <= 10^8). 分析:此题相对于本节"寻找满 ...

  3. 【POJ】2449.Remmarguts' Date(K短路 n log n + k log k + m算法,非A*,论文算法)

    题解 (搬运一个原来博客的论文题) 抱着板题的心情去,结果有大坑 就是S == T的时候也一定要走,++K 我发现按照论文写得\(O(n \log n + m + k \ log k)\)算法没有玄学 ...

  4. LeetCode OJ:Reverse Nodes in k-Group(K个K个的分割节点)

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...

  5. UVA 1363 Joseph's Problem 找规律+推导 给定n,k;求k%[1,n]的和。

    /** 题目:Joseph's Problem 链接:https://vjudge.net/problem/UVA-1363 题意:给定n,k;求k%[1,n]的和. 思路: 没想出来,看了lrj的想 ...

  6. js为Object对象动态添加属性和值 eval c.k c[k]

    const appendInfo = () => { const API_SECRET_KEY = 'https://github.com/dyq086/wepy-mall/tree/maste ...

  7. d[k]=eval(k)

    lk = ['oid', 'timestamp', 'signals', 'area', 'building', 'city', 'name', 'floor', 'industry', 'regio ...

  8. bzoj3028食物 关于(1+x+x2+x3+x4+...)^k的第i项系数就是c(i+k−1,k−1)的证明

    关于(1+x+x2+x3+x4+...)^k的第i项系数就是c(i+k−1,k−1)的证明对于第i项,假设为5x^5=x^0*x^5x^5=x^1*x^4x^5=x^2*x^3........也就是说 ...

  9. python代码{v: k for k, v in myArray.items()}是什么意思?

    最近在扒vnpy的源码总能看到{v: k for k, v in ORDERTYPE_VT2HUOBI.items()}这样的源码,就是不知道什么意思 然后万能的google找到了Quora的一个类似 ...

  10. 解析形如(k,v)(k,v)(k,v)字符串

    有时根据需要会将map数据格式化成(k,v)(k,v)(k,v)--字符串,之后需要还原,下面代码实现了还原过程 1 void SplitString(const string& s, vec ...

随机推荐

  1. c++ 深度优先算法

    #include <iostream> using namespace std; #define VertexNum 9 /*定义顶点数*/ struct Node /*声明图形顶点结构* ...

  2. 吴裕雄--天生自然MySQL学习笔记:MySQL WHERE 子句

    MySQL 表中使用 SQL SELECT 语句来读取数据. 如需有条件地从表中选取数据,可将 WHERE 子句添加到 SELECT 语句中. 语法 以下是 SQL SELECT 语句使用 WHERE ...

  3. Flink(四) —— 数据流编程模型

    分层抽象 The lowest level abstraction simply offers stateful streaming. It is embedded into the DataStre ...

  4. Elastic ik插件配置热更新功能

    ik github地址:https://github.com/medcl/elasticsearch-analysis-ik 官网说明: 热更新 IK 分词使用方法 目前该插件支持热更新 IK 分词, ...

  5. ZOJ 3735 dp

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3735 好久没做DP题了,一开始没理解题目里的C(M,3)是干什么,原来就是 ...

  6. 代码杂谈-split函数

    java split 函数默认会清除空白行尾的空白. 为了避免这个问题, 需要加参数, 改为 String[] tmpValues = line.split(",", -1);

  7. vue-router中参数传递

    VUE路由之间携带参数 今天在实现一个功能的时候遇到的问题,一个把组件a中的值传输到组件b中时,但是组件a和组件b之间通信的时候路由跳转了 猜想:路由跳转导致监听事件失败,(暂时理解为:当路由跳转后监 ...

  8. webpack快速使用笔记

    一.NPM1.NPM是随同NodeJS一起安装的包管理工具. http://www.1994july.club/?p=14542.安装npm install npm -gnpm -v 测试是否成功安装 ...

  9. 【范式与函数依赖】3NF与BCNF的区别

    *本文中码指代候选码,主属性为构成码的属性. 先简要引入几个概念 图1 图2 单拿出来我认为不是很好理解的3NF和BCNF详细的说说. 书上写了,BCNF是完善后的3NF.从图2中显然得出,1-3NF ...

  10. 一个理解基本RCNN的简单例子

    对于一个最简单的RNN网络https://github.com/Teaonly/beginlearning/ """Minimal character-level Van ...