本文共 646 字,大约阅读时间需要 2 分钟。
提示 ,如果下一次排序完成的状态和上一次相同继续排列,最多排列N次。
#include#include #include #include #include #include #include using namespace std;void judge (vector targetSequence,int pos,bool &kind){ for(int i=0; i targetSequence[i+1]) { kind = false; break; } }}int main(){ int n; scanf("%d",&n); vector initSequence(n); vector targetSequence(n); for(int i=0; i =0; --i) { if(initSequence[i]!=targetSequence[i]) { pos = i; break; } } bool isInsert = true; judge(targetSequence,pos,isInsert); vector next = targetSequence; if(isInsert) { for(int i = pos+1;i 0; i--) { if(targetSequence[i]
转载地址:http://wqhji.baihongyu.com/