1、从左边开始,找到一个满足左边小于自己的数a
2、从这个数a开始向右找,找到一个最小的比a打的数,两者交换
3、把从a开始向右的所有数用qsort从小到大排个序
[cpp]#include <iostream>
using namespace std;
void nextPermutation(int a[],int n);
int myCompare(const void *a,const void *b);
void exchange(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void nextPermutation(int a[],int n)
{
int i;
for(i=n;i>0&&a[i-1]>a[i];i–);
if(i==0) {
for(i=1;i<=n;i++)
a[i]=i;
return;
}
int j,*min;
min=&a[i];
for(j=i+1;j<=n;j++) {
if(*min>a[j]&&a[j]>a[i-1])
min=&a[j];
}
exchange(a+i-1,min);
qsort(a+i,n-i+1,sizeof(int),myCompare);
}
int myCompare(const void *a,const void *b)
{
return *((int*)a)-*((int*)b);
}
int main()
{
int a[1024];
int n,k;
int N,i;
a[0]=2000;
scanf("%d",&N);
while(N–) {
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=0;i<k;i++)
nextPermutation(a,n);
for(i=1;i<=n-1;i++)
cout<<a[i]<<" ";
cout<<a[n]<<endl;
}
}
[/cpp]
1000MS正好AC
下面这个是用的STL的库函数 耍流氓
[cpp]#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
int a[1024];
int n,k;
int N;
scanf("%d",&N);
while(N–) {
scanf("%d%d",&n,&k);
int i;
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
int *start=a+1;
int *end=a+n+1;
for(i=0;i<k;i++)
next_permutation(start,end);
for(i=1;i<=n-1;i++)
cout<<a[i]<<" ";
cout<<a[n]<<endl;
}
}
[/cpp]
References:
KingMaker Casino Einzahlung per Giropay http://cse.google.com.tr
References:
KingMaker einzahlung skrill https://fishing-ua.com/proxy.php?link=https://sosi.al/chauadkins7371
References:
Legiano Casino Mindestauszahlung https://book.douban.com/
References:
KingMaker Casino Einzahlung per Lastschrift http://maps.google.ge/url?sa=t&url=https://sysurl.online/tobiashallen18
References:
KingMaker Casino App Download http://maps.google.mw
References:
Hitnspin casino auszahlungslimit ntis.gov
References:
Hitnspin verifizierung abb.eastview.com
References:
Monro Casino Anmeldung https://forums-archive.eveonline.com/warning/?l=https://sbfpageing.com/hiyzm&domain=nyikunyit.com
References:
Monro Casino Slots globalnews.ca
References:
Hitnspin bewertung angelstammtisch.de
References:
Hitnspin freispiele http://www.google.com.ua
References:
Hitnspin kundensupport http://suhl.com/adserver/cgi-bin/adiscount.php?adid=theresienfest&url=http://illustrators.ru/away?link=https://de.trustpilot.com/review/der-wikinger-shop.de
References:
Hitnspin casino ähnliche casinos http://wiki.kaskady2.cz
References:
Hitnspin casino erfahrungen hanabijin.jp
References:
Hitnspin gutscheincode https://soundingames.dei.uc.pt/api.php?action=bom.so/xf4Ovihttps://platform.joinus4health.eu/forums/users/suiteffect26/
References:
Hit n spin bonus ohne einzahlung https://www.xvlivecams.com/
References:
Hitnspin casino kundenbewertungen rmnt.ru
References:
Hitnspin casino willkommensbonus perevodvsem.ru
References:
Hitnspin casino auszahlung redirect.camfrog.com
References:
Hitnspin login http://hotubi.com/go.php?url=https://hotgirlsforum.com/member.php?action=profile&uid=200274
References:
Hitnspin casino sicher https://www.playground.ru/redirect/spd.link/eltonglees
References:
Hit’n’spin casino 25 euro bonus ohne einzahlung plitkat.ru
References:
Hit n spin casino http://domfialki.ru/bitrix/click.php?goto=https://chesswiki.site/wiki/HitNSpin_Casino_Bewertung_Aktionen_und_Willkommensbonus
References:
Lollybet No Deposit Bonus http://reshalkino.ru/proxy.php?link=http://domfialki.com/bitrix/click.php?goto=https://lollybet.com.de/
References:
Lollybet Registrierung http://maps.google.com.om/url?q=https://r.pokupki21.ru/redir.php?https://lollybet.com.de/
References:
Lollybet Online Casino http://www.google.com.kw/url?q=http://www.xcnews.ru/go.php?go=lollybet.com.de
References:
Lollybet Casino Login http://maps.google.ci/url?q=https://may22.ru/user/pricesweets3/
References:
Lollybet Casino DE live.warthunder.com
References:
Lollybet Casino Seriös http://es.thefreedictionary.com/_/cite.aspx?url=http://filelist.io/redir.php?https://lollybet.com.de/&word=apostata&sources=vox_manual,vox1,kdict,vox_thes,open_thes,hc_Es_En
References:
Lollybet Freispiele google.im
I am extremely impressed with your writing skills and also
with the layout on your weblog. Is this a paid theme or did you customize it yourself?
Either way keep up the excellent quality writing,
it’s rare to see a nice blog like this one nowadays.
of course like your website but you have to check
the spelling on quite a few of your posts. Several of them are rife with spelling problems
and I to find it very bothersome to tell the truth however I’ll surely come back again.
This is very attention-grabbing, You’re an overly professional blogger.
I’ve joined your feed and look forward to seeking more of your magnificent post.
Additionally, I have shared your site in my social networks
At this time I am going to do my breakfast, when having
my breakfast coming over again to read other news.
References:
Hit n spin casino bonus http://cse.google.com.au/
References:
Hitnspin casino anmeldung http://clients1.google.ge
This is very interesting, You are a very skilled blogger.
I have joined your feed and look forward to seeking more of your magnificent post.
Also, I’ve shared your website in my social networks!
Hello! Do you know if they make any plugins to help
with SEO? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains.
If you know of any please share. Thanks!
References:
Hit n spin casino erfahrungen cse.google.co.id
References:
Hitspin casino http://clients1.google.co.ug/
References:
Hitnspin casino spielautomaten image.google.sh
What’s up everyone, it’s my first pay a quick visit at this web page, and paragraph is genuinely fruitful
in favor of me, keep up posting these types of content.
Hey! Someone in my Myspace group shared this site
with us so I came to give it a look. I’m definitely enjoying the information. I’m book-marking and will be
tweeting this to my followers! Outstanding blog
and amazing design.
Heya i am for the first time here. I found this board and I find It truly useful & it helped me out a
lot. I hope to give something back and help others like you
aided me.
References:
Hitnspin auszahlung dauer http://clients1.google.rw/url?q=http://csmouse.com/user/packetfender65/
References:
Hitnspin casino app iphone images.google.com.ai
Remarkable! Its genuinely remarkable post, I have got much clear
idea about from this post.
Heya! I realize this is somewhat off-topic however I had to ask.
Does operating a well-established website such
as yours take a lot of work? I am completely new to running a blog however
I do write in my journal daily. I’d like to start a blog so I will be able to share my personal experience
and views online. Please let me know if you have any
kind of suggestions or tips for brand new aspiring bloggers.
Thankyou!
This design is steller! You most certainly know how to keep a
reader entertained. Between your wit and your videos, I was
almost moved to start my own blog (well, almost…HaHa!) Wonderful
job. I really enjoyed what you had to say, and more than that, how you presented it.
Too cool!
Hi there to every body, it’s my first visit of this blog; this webpage carries amazing and genuinely excellent data designed
for visitors.