简述:给你一个数组,判断是否能拆分成2个数组,一个递增一个递减,若不行输出No,可以就Yes并分别输出
思路:统计每个数出现的次数,若有大于2的肯定无法组成严格单调,这样就只需要将出现两次的组成递,剩下的递减即可
代码:
#include<iostream> #include<algorithm> #include<cstdio> #include<vector> #include<set> #include<map> using namespace std; //const int maxm = 2019; //int buff[maxm]; map<int,int> sum; int main() { int n; scanf("%d",&n); getchar(); for(int i = 0;i < n;++i) { int tmp; scanf("%d",&tmp); ++sum[tmp]; } bool flag = true; int dbnum = 0; for(auto i = sum.begin();i != sum.end(); ++i) { if(i->second == 2)++dbnum; if(i->second > 2) { flag = false; break; } } if(!flag) printf("NO"); else { printf("YES "); printf("%d ",dbnum); for(auto i = sum.begin(); i != sum.end(); ++i) { if(i->second == 2) cout << i->first << ' '; } printf(" "); printf("%d ",n-dbnum); for(auto i = sum.rbegin();i != sum.rend();++i) { cout << i->first << ' '; } printf(" "); } return 0; }