zoukankan      html  css  js  c++  java
  • Codeforces1144C(C题)Two Shuffled Sequences

    C. Two Shuffled Sequences

    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][x1<x2<⋯<xk]. And strictly decreasing sequence is a sequence of integers [y1>y2>>yl][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 aaaaaa[1,3,4][1,3,4][10,4,2][10,4,2][1,2,3,4,4,10][1,2,3,4,4,10][4,2,1,10,4,3][4,2,1,10,4,3]

    This shuffled sequence aa 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 aa to increasing and decreasing sequences, print "NO".

    Input

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

    The second line of the input contains nn integers a1,a2,,ana1,a2,…,an (0ai21050≤ai≤2⋅105), where aiai is the ii-th element of aa.

    Output

    If there is a contradiction in the input and it is impossible to split the given sequence aa

    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 nininini

    In the third line print niniinc1,inc2,,incniinc1,inc2,…,incniinc1<inc2<<incniinc1<inc2<⋯<incnini=0ni=0

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

    In the fifth line print ndnddec1,dec2,,decnddec1,dec2,…,decnddec1>dec2>>decnddec1>dec2>⋯>decndnd=0nd=0

    ni+ndni+ndn

    代码:

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<set>
     4 using namespace std;
     5 int main() {
     6     int zen[1000000],b[1000000],c[1000000];
     7     int n,zhi,count=0,jishu2=0;
     8     cin>>n;
     9     set<int> a,d;
    10     for(int i=0; i<n; i++) {
    11         cin>>zhi;
    12         if(a.count(zhi)) {
    13             c[jishu2++]=zhi;
    14             if(d.count(zhi)) {
    15                 cout<<"No";
    16                 return 0;
    17             }
    18             d.insert(zhi);
    19         }
    20         a.insert(zhi);
    21         b[i]=zhi;
    22     }
    23     for(set<int>::iterator it=a.begin(); it!=a.end(); it++) {
    24         zen[count++]=*it;
    25     }
    26     sort(zen,zen+count,greater<int>());
    27     sort(c,c+jishu2);
    28     cout<<"Yes"<<endl;
    29     cout<<jishu2<<endl;
    30     for(int i=0; i<jishu2; i++) {
    31         cout<<c[i]<<" ";
    32     }
    33     cout<<endl;
    34     cout<<count<<endl;
    35     for(int i=0; i<count; i++) {
    36         cout<<zen[i]<<" ";
    37     }
    38     cout<<endl;
    39 }

    思路分析:先将所有数存集合中,然后将集合中数存到个数组中再对数组从大到小排序。然后便利,将集合中已存在元素存到新数组中作为递增序列。

    题目链接:https://codeforces.com/contest/1144/problem/C

  • 相关阅读:
    让linux下的eclipse支持GBK编码
    Ubuntu 14.04 安装深度音乐的方法(下载速度极慢未成功)
    wine使用
    Sql语句查看表结构
    读数据库所有表和表结构的sql语句
    详解软件工程之软工文档
    浅谈UML的概念和模型之UML九种图
    HTML5 file api读取文件的MD5码工具
    Sublime Text 3 快捷键汇总
    领域驱动设计系列文章汇总
  • 原文地址:https://www.cnblogs.com/yuanhang110/p/11255906.html
Copyright © 2011-2022 走看看