题目描述

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弄上去

排除不可能的解

最新文章

  1. 【Excel 4.0 函数】REGISTER
  2. swiper的使用
  3. Pro ASP.NET MVC 5 Framework.学习笔记.6.4.MVC的必备工具
  4. [安卓][转]Android eclipse中程序调试
  5. GBin1插件推荐之马可波罗(Marco Polo),jQuery的自动补齐插件 - Autocomplete Plugin
  6. 简单又强大的联发科手机PhilZ Touch Recovery安装器,详细教程 - 本文出自高州吧
  7. Eclipse中快捷键的使用
  8. (大数据工程师学习路径)第一步 Linux 基础入门----用户及文件权限管理
  9. 当Azure里的虚拟机网卡被禁用
  10. calling c++ from golang with swig--windows dll (三)
  11. java项目和java-web项目中文件和文件夹的含义
  12. Visual Studio2012 添加服务引用时,生成基于任务操作不可用原因
  13. Vue-admin工作整理(八): BUS | | 组件通信
  14. Julia 下载 安装 juno 开发环境搭建
  15. NLP总览
  16. Hadoop集群搭建笔记
  17. as和is,但is也有as所没有的功能[C#] --转载 甘木
  18. 清北冬令营入学测试[ABCDEF]
  19. libcurl库的编译
  20. mask layer的遮罩层

热门文章

  1. 运行xv6
  2. h5-web字体和字体图标
  3. Navicat Premium 12.0.18 安装与激活
  4. String StringBuffer和StringBuilder的区别和联系
  5. 吴裕雄--天生自然JAVA线程编程笔记:进程与线程
  6. JAVA课程设计——俄罗斯方块
  7. spring容器抽象的具体实现
  8. Java 面向对象概述原理: 多态、Object类,转型(8)
  9. Spring Bean的生命周期、Spring MVC的工作流程、IOC,AOP
  10. JavaScript sort()方法总结