题目链接:http://codeforces.com/problemset/problem/1144/C
思路:
就是将序列中个数为2的数字排为升序,剩下的都是降序,如果有个数为3的数字,就输出NO
AC代码
#include<iostream> #include<algorithm> using namespace std; const int MAX=2e5+10; int a[MAX],b[MAX]; int ans1[MAX],ans2[MAX]; bool cmp(int a,int b){ return a>b; } int main() { int n; cin>>n; int num,flag=0; for(int i=0;i<n;i++) { cin>>a[i]; b[a[i]]++; if(b[a[i]]==3)flag=1; } if(flag==1){ cout<<"NO"<<endl; return 0; } sort(a,a+n,cmp); int count1=0,count2=0; ans1[count1++]=a[0]; for(int i=1;i<n;i++) { if(a[i]==a[i-1]) { ans2[count2++]=a[i]; }else ans1[count1++]=a[i]; } cout<<"YES"<<endl; cout<<count2<<endl; for(int i=count2-1;i>=0;i--)cout<<ans2[i]<<" "; cout<<endl; cout<<count1<<endl; for(int i=0;i<count1;i++)cout<<ans1[i]<<" "; return 0; }
CSU-暑假集训题 C - Two Shuffled Sequences CodeForces - 1144C
原文:https://www.cnblogs.com/xlbfxx/p/11255419.html