C. Two Shuffled Sequences

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Two integer sequences existed initially — one of them was strictly increasing, and the other one — strictly decreasing.

Strictly increasing sequence is a sequence of integers [x1<x2<⋯<xk]. And strictly decreasing sequence is a sequence of integers [y1>y2>⋯>yl]. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

They were merged into one sequence a. After that sequence a got shuffled. For example, some of the possible resulting sequences a for an increasing sequence [1,3,4] and a decreasing sequence [10,4,2] are sequences [1,2,3,4,4,10] or [4,2,1,10,4,3].

This shuffled sequence a is given in the input.

Your task is to find any two suitable initial sequences. One of them should be strictly increasing and the other one — strictly decreasing. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

If there is a contradiction in the input and it is impossible to split the given sequence a to increasing and decreasing sequences, print “NO”.

Input
The first line of the input contains one integer n (1≤n≤2⋅105) — the number of elements in a.

The second line of the input contains n integers a1,a2,…,an (0≤ai≤2⋅105), where ai is the i-th element of a.

Output
If there is a contradiction in the input and it is impossible to split the given sequence a to increasing and decreasing sequences, print “NO” in the first line.

Otherwise print “YES” in the first line and any two suitable sequences. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

In the second line print ni — the number of elements in the strictly increasing sequence. ni can be zero, in this case the increasing sequence is empty.

In the third line print ni integers inc1,inc2,…,incni in the increasing order of its values (inc1<inc2<⋯<incni) — the strictly increasing sequence itself. You can keep this line empty if ni=0 (or just print the empty line).

In the fourth line print nd — the number of elements in the strictly decreasing sequence. nd can be zero, in this case the decreasing sequence is empty.

In the fifth line print nd integers dec1,dec2,…,decnd in the decreasing order of its values (dec1>dec2>⋯>decnd) — the strictly decreasing sequence itself. You can keep this line empty if nd=0 (or just print the empty line).

ni+nd should be equal to n and the union of printed sequences should be a permutation of the given sequence (in case of “YES” answer).

Examples
inputCopy
7
7 2 7 3 3 1 4
outputCopy
YES
2
3 7
5
7 4 3 2 1
inputCopy
5
4 3 1 5 3
outputCopy
YES
1
3
4
5 4 3 1
inputCopy
5
1 1 2 1 2
outputCopy
NO
inputCopy
5
0 1 2 3 4
outputCopy
YES
0

5
4 3 2 1 0

思路:两个数组,一个递增,一个递减,随机合成一起,现在给你这个数组,问是否可以拆出去

因为这两个数组完全递增或递减,所以合成的数组中不可能出现三个相同的数

我这个写的很多但是应该挺好懂

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int a[200005];//用来存合成序列
int b[200005];//用来存递增序列
int c[200005];//用来存递减序列
int main(){int n;int i;while(scanf("%d",&n)!=EOF){int count1=0;//用来存递减序列的个数int count2=0;//用来存递增序列的个数int flag=0;//用来判断数组中是否有三个相同的数int w=0;//数组c的下标int v=0;//数组b的下标for(i=0;i<n;i++){scanf("%d",&a[i]);}sort(a,a+n); //sort排序if(n==1){        //如果n==1的时候,就直接去按格式输出printf("YES\n");      //别忘了YES,因为这个我WA了四次!!!!!!,就是它!!!!!printf("0\n");                           //哭唧唧printf("\n");                            //想到了伤心往事,后面的注释不写了,自己看去!printf("1\n");printf("%d\n",a[0]);continue;}for(i=0;i<n-2;i++){if(a[i]==a[i+1]){if(a[i]==a[i+2]){flag=1;break;}}}if(flag==1){printf("NO\n");continue;}else{printf("YES\n");}for(i=0;i<n-1;i++){if(a[i]!=a[i+1]){c[w]=a[i];count1++;w++;if(i==n-2){c[w]=a[i+1];count1++;}}else{c[w]=a[i];b[v]=a[i+1];i++;count1++;count2++;w++;v++;if(i==n-2){c[w]=a[i+1];count1++;}}}if(count2==0){printf("0\n");printf("\n");}else{printf("%d\n",count2);for(i=0;i<count2-1;i++){printf("%d ",b[i]);}printf("%d\n",b[count2-1]);}printf("%d\n",count1);for(i=count1-1;i>0;i--){printf("%d ",c[i]);}printf("%d\n",c[0]);}return 0;
}

Two Shuffled Sequences相关推荐

  1. DAY1 Two Shuffled Sequences

    C. Two Shuffled Sequences time limit per test2 seconds memory limit per test256 megabytes inputstand ...

  2. C. Two Shuffled Sequences

    Two integer sequences existed initially - one of them was strictly increasing, and the other one - s ...

  3. CodeForces - 1144C Two Shuffled Sequences【优先队列】

    Two Shuffled Sequences 题意: 将给定数组分成两组,其中一组严格递增,另一组严格递减. 题解: 要点在于数组中元素必须是严格递增或递减的,就是说一个元素不能在一个数组中重复出现. ...

  4. Codeforces Round #550 (Div. 3) C.Two Shuffled Sequences

    C. Two Shuffled Sequences Two integer sequences existed initially - one of them was strictly increas ...

  5. Codeforces1144C(C题)Two Shuffled Sequences

    C. Two Shuffled Sequences Two integer sequences existed initially - one of them was strictly increas ...

  6. Codeforces Round #550 (Div. 3)C. Two Shuffled Sequences

    Two integer sequences existed initially - one of them was strictly increasing, and the other one - s ...

  7. 1144C C. Two Shuffled Sequences(优先队列和set的应用)

    Two integer sequences existed initially - one of them was strictly increasing, and the other one - s ...

  8. CodeForces1144 C - Two Shuffled Sequences

    题目: 传送门 思路: 判断是否有一个数重复了三次以上,如果有则不能构成,然后将所给序列从小到大排序,取一个上升的序列,剩下的数从大往小就下降的序列,输出即可 vector<int> v1 ...

  9. CF1144C - Two Shuffled Sequences

    题意:把一个序列分成完全递增和完全递减的两个序列(即不可有相等的两个数),无元素或者只有一个元素也可认为是递增或递减,可行则按要求输出,不可行则输出NO. 题解:看有没有数字重复三次或以上的,若只出现 ...

最新文章

  1. 虚拟机linux 8.04汉化,在虚拟机中快速安装 Ubuntu 18.04
  2. 64 oracle client,64bit oracle and oracle client.
  3. 为什么刹车热了会失灵_汽车为什么要换刹车油?
  4. 装饰器 闭包 生成器 迭代器
  5. 教你如何察觉出网络钓鱼电子邮件
  6. 基于事件驱动架构构建微服务第2部分:领域对象和业务规则
  7. Matplotlib 中文用户指南 3.9 路径效果指南
  8. linux先安装svn server
  9. JAVA设计模式(08):结构化-飞锤(Flyweight)
  10. 面试题之wait()和sleep()方法区别
  11. 阿里云iconfont使用方法
  12. matlab音频指纹识别_指纹识别算法matlab实现.doc
  13. LTE FDD 时频资源
  14. stm32f103c6t6
  15. js练习(十一)实现一个打点计时器 setInterval()
  16. 大数据之足球盘口赔率凯利必发数据采集爬虫
  17. 不要虚掷你的黄金时代,不要去倾听枯燥乏味的东西,不要设法挽留无望的失败,不要把你的生命献给无知、平庸和低俗。
  18. 数据结构童话版 003新的学生
  19. FileInputStream与BufferedInputStream的区别
  20. 终端插双电信卡都能打电话么?

热门文章

  1. 社交产品分析:共同看片,微光
  2. 使用BitLocker实现磁盘加密、u盘加密、移动硬盘加密
  3. 从0开始,手把手搭建个人网站
  4. 三步必杀(P4231)
  5. 【OpenStreetMap】任意城市道路数据下载(附带数据解释)
  6. 区块链学习2——区块链浏览器的搭建
  7. 【Golang】golang开发微信公众号网页授权功能
  8. 图形学篇:多边形有效边表填充算法
  9. pygame: libpng warning: iCCP: known incorrect sRGB profile 报错
  10. 团体程序设计天梯赛-练习集-L1-031. 到底是不是太胖了