codeforces MUH and Important Things

 /*
   题意:给一个序列,表示每一项任务的难度,要求完成每一项任务的循序是按照难度由小到大的!输出三种符合要求的工作顺序的序列!
   思路:直接看代码....
*/
1
#include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #define N 2005 6 using namespace std; 7 struct node{ 8 int h; 9 int p; 10 }; 11 12 node nd[N]; 13 14 int vis[N]; 15 16 bool cmp(node a, node b){ 17 return a.h < b.h; 18 } 19 20 void swap(int *p, int *q){ 21 int t = *p; 22 *p = *q; 23 *q = t; 24 } 25 26 int main(){ 27 int n; 28 scanf("%d", &n); 29 for(int i=1; i<=n; ++i){ 30 scanf("%d", &nd[i].h); 31 nd[i].p=i; 32 } 33 sort(nd+1, nd+n+1, cmp); 34 int cnt = 0; 35 for(int i=1; i<n; ++i){ 36 for(int j=i+1; j<=n; ++j) 37 if(nd[i].h == nd[j].h) 38 ++cnt;//找到有多少对数相同的 39 else{ i=j-1; break; } 40 } 41 42 43 if(cnt<2) cout<<"NO"<<endl;//如果少于两对,一定不能 44 else{ 45 cout<<"YES"<<endl; 46 cout<<nd[1].p; 47 for(int i=2; i<=n; ++i)//输出源序列 48 cout<<" "<<nd[i].p; 49 cout<<endl; 50 int p; 51 for(int i=1; i<n; ++i) 52 if( nd[i].h == nd[i+1].h){//找到第一对相同的交换位置 53 p = i; 54 swap(&nd[i].p, &nd[i+1].p); 55 break; 56 } 57 cout<<nd[1].p; 58 for(int i=2; i<=n; ++i) 59 cout<<" "<<nd[i].p; 60 cout<<endl; 61 for(int i=1; i<n; ++i)//找到第二对相同的交换位置 62 if( nd[i].h == nd[i+1].h && i != p){ 63 swap(&nd[i].p, &nd[i+1].p); 64 break; 65 } 66 67 cout<<nd[1].p; 68 for(int i=2; i<=n; ++i) 69 cout<<" "<<nd[i].p; 70 cout<<endl; 71 } 72 73 return 0; 74 }
原文地址:https://www.cnblogs.com/hujunzheng/p/3996118.html