题目描述

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. SpringMVC的配置文件说明

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. MySQL空洞问题解决

    原因:Mysql对于BLOB/TEXT值在执行大量删除操作时可能会引起空洞.空洞就是数据虽然删除了,但是依然占用服务器物理空间,会导致性能底下. 解决办法:定期使用OPTIMIZE TABLE进行碎片 ...

  3. [C/C++]C/C++计算代码的运行时间

    有很多时候,实现一个功能后可能不仅仅要效果,还要效率,如果可以在极短的时间内完成一个功能那当然是最好不过的啦,但是可能经常会事与愿违. 这里就写一下,都可以怎样用C/C++或者Qt的方法来测试代码的运 ...

  4. LeetCode——456.132模式

    给定一个整数序列:a1, a2, ..., an,一个132模式的子序列 ai, aj, ak 被定义为:当 i < j < k 时,ai < ak < aj.设计一个算法,当 ...

  5. console.log和alert的区别

    alert是同步的,如果不关闭弹出框,js代码就不会继续执行下去,这时候浏览器啥都干不了. console.log不会打断js的执行. 当要输出几十几百条信息的时候还是得用console.log,而且 ...

  6. Window RabbitMq安装

    rabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统.它遵循Mozilla Public License开源协议,采用 Erlang 实现的工业级的消息队列(MQ)服务器,Rab ...

  7. pix2pix-tf官方文档

    # 对抗网络的基本思想 # 假设有一种概率分布M,它相对于我们是一个黑盒子.为了了解这个黑盒子中的东西是什么,我们构建了两个东西G和D, # G是另一种我们完全知道的概率分布,D用来区分一个事件是由黑 ...

  8. centos7 安装gdb (调试nginx)

    首先卸载原有的gdb,sudo yum remove gdb 从gnu官网下载最新的gdb源文件,wget http://mirrors.ustc.edu.cn/gnu/gdb/gdb-7.9.1.t ...

  9. Python笔记_第三篇_面向对象_7.多态

    1. 多态的概念 多态:一种事物的多种形态.其表现形式就是连续的继承关系. 还以人喂食动物的例子.最终目标是人可以喂食任何一种动物.如果人要喂食100多种动物,难道要写100中方法吗?多态就是把属性和 ...

  10. 封装FTP类

    using System; using System.Net; using System.Net.Sockets; using System.Text; using System.IO; using ...