题目描述

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. clion 的 安装 变量配置的 搬运工(有点基础应该能看 大家看不懂 就是我自己看 哈哈哈哈哈哈)

    1  自行安装一个  clion 2 https://blog.csdn.net/u013023297/article/details/80723847   mingw  的配置    第二篇好像当时 ...

  2. C++逐行读取txt

    C++读取txt文件的时候可以使用std::ifstream来实现,如果打开文件失败的话,其变量会是空的,所以可以用来判断是否打开成功.  #include <stdlib.h>  #in ...

  3. 记录 TypeError: render() got an unexpected keyword argument 'renderer' 错误

    在网上看到MXShop这个项目,适合Python, Django + drf 进阶的,其中遇到 TypeError: render() got an unexpected keyword argume ...

  4. Api_hook 拦截 messageBox 等函数

    library hookdll; uses SysUtils, Windows, Classes, unitHook in 'unitHook.pas'; {$R *.res} const HOOK_ ...

  5. HTML5 Canvas——折线图

    <script type="text/javascript"> /*1.绘制网格 网格大小 10px 网格的颜色 #ddd */ /*2.绘制坐标 轴的离边距离 20p ...

  6. windows更新系统系统时无法更新

    win7系统显示“windows update当前无法检查更新,因为未运行服务,您可能需要重新启动计算机” 解决方法 1.win+r打开运行窗口,输入CMD 2.在dos窗口中输入命令“net sto ...

  7. malloc函数、calloc函数和free函数

    malloc函数和free函数 malloc函数原型:void *malloc(long NumBytes) malloc原型说明:mallco函数在堆分配了NumBytes个字节的内存空间,用来存放 ...

  8. 从编程实现角度学习Faster R-CNN(附极简实现)

    https://www.jianshu.com/p/9da1f0756813 从编程实现角度学习Faster R-CNN(附极简实现) GoDeep 关注 2018.03.11 15:51* 字数 5 ...

  9. chrome安装switchyomega

    由于在国外网站找不到下载链接,在国内招了个crx文件,以下为安装crx教程 首先修改后缀为zip,再解压, 得到以下文件 然后在chrome里找到扩展程序, 打开开发者模式,点击-加载已解压的扩展程序 ...

  10. Spring MVC中防止csrf攻击

    Spring MVC中防止csrf攻击的拦截器示例 https://blog.csdn.net/qq_40754259/article/details/80510088 Spring MVC中的CSR ...