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

  • 相关阅读:
    3名百度 ,京东,腾讯被辞退的高级Android工程师现在怎么了?30岁真的是“罪”吗
    Python 开发者在迁移到 Go 前需要知道的事情
    centos7 常用命令--查看当前用户的4种方法
    Centos7找不到ifconfig和netstat命令
    Centos 7 修改日期和时间的命令
    如何利用MobaX同时处理多台虚拟机输入相同命令如何利用MobaX同时处理多台虚拟机输入相同命令
    配置坑了我好久:Logback按天生成文件失效
    quartz系列文章
    SpringBoot使用多实例QUARTZ出现重复执行问题
    IDEA多个springboot项目启动修改端口
  • 原文地址:https://www.cnblogs.com/yuanhang110/p/11255906.html
Copyright © 2011-2022 走看看