POJ1833 解题报告, 模拟

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]

160 thoughts on “POJ1833 解题报告, 模拟

  1. 나루토

    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.

    Reply
  2. NRI Online Legal Consultancy

    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.

    Reply
  3. 카지노입플

    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

    Reply
  4. 강남데이트코스

    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!

    Reply
  5. nsfw

    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!

    Reply
  6. Qwen

    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.

    Reply
  7. 메리나잇

    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.

    Reply
  8. Pottery Barn

    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!

    Reply
  9. คาสิโนออนไลน์

    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!

    Reply
  10. Hentai

    Hi there to every body, it’s my first visit of this blog; this webpage carries amazing and genuinely excellent data designed
    for visitors.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *