1 solutions
-
0
C++ :
#include<bits/stdc++.h> using namespace std; const int N=10010; int n,m; int q[N]; int main() { cin>>n>>m; for(int i=0;i<n;i++) cin>>q[i]; while(m--) { //找到第一个变化能最小改变序列的位置 int k=n-2; while(q[k]>q[k+1]) k--; //找到改变这个数的数 int t=k+1; while(t+1<n && q[t+1]>q[k]) t++; swap(q[t],q[k]); //将后面从降序转为升序 reverse(q+k+1,q+n); } for(int i=0;i<n;i++) cout<<q[i]<<' '; cout<<endl; return 0; }
- 1
Information
- ID
- 17309
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By