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. JAV

    If some one needs to be updated with latest technologies then he must be go to
    see this web page and be up to date daily.

    Reply
  2. mostbet deposit

    Hi there, i read your blog from time to time and i own a similar
    one and i was just wondering if you get a lot of spam
    remarks? If so how do you reduce it, any plugin or
    anything you can advise? I get so much lately it’s driving me insane so any assistance is very much appreciated.

    Reply
  3. purdentix dental supplement

    I’d like to thank you for the efforts you have put in writing this
    site. I’m hoping to see the same high-grade
    blog posts from you in the future as well. In fact, your creative writing abilities has motivated me to get my own,
    personal blog now 😉

    Reply
  4. slim force health benefits

    I’m impressed, I must say. Seldom do I come across
    a blog that’s both equally educative and engaging, and let
    me tell you, you have hit the nail on the head.
    The problem is something too few people are speaking intelligently
    about. I’m very happy I found this in my hunt for something relating to this.

    Reply
  5. pulmo balance cost

    I just could not depart your web site before suggesting that I
    really enjoyed the standard information an individual supply in your visitors?

    Is going to be back steadily to inspect new
    posts

    Reply
  6. สนุ้กเกอร์

    Just want to say your article is as amazing. The clarity on your put up is simply spectacular and
    i could assume you are an expert in this subject.
    Fine along with your permission allow me to
    snatch your feed to stay up to date with forthcoming post.

    Thanks 1,000,000 and please keep up the rewarding
    work.

    Reply
  7. Sascu Credit Union

    Hello are using WordPress for your blog platform? I’m new to the blog world
    but I’m trying to get started and create my own. Do you need any html coding expertise to make your own blog?
    Any help would be really appreciated!

    Reply
  8. เย็ดสบัด

    When I initially left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on every time
    a comment is added I receive four emails with the same comment.
    Perhaps there is an easy method you are able to remove
    me from that service? Cheers!

    Reply
  9. Servus Credit Union

    Do you mind if I quote a few of your posts as long
    as I provide credit and sources back to your site? My blog is in the very same niche as yours and my users would definitely benefit from some of the information you provide
    here. Please let me know if this ok with you.

    Many thanks!

    Reply
  10. Target House Brand

    Definitely believe that which you stated. Your favorite justification appeared to be
    at the net the simplest factor to keep in mind of. I say to you, I definitely get
    irked while folks think about concerns that they plainly do not recognise about.
    You managed to hit the nail upon the highest and also defined out the entire thing with no need side-effects ,
    people could take a signal. Will probably be
    back to get more. Thank you

    Reply
  11. SCU

    It’s not my first time to pay a quick visit this web site, i am visiting this web page dailly and get good facts from here everyday.

    Reply
  12. MALWARE

    Fascinating blog! Is your theme custom made or did you download
    it from somewhere? A design like yours with a few simple adjustements would really make my
    blog shine. Please let me know where you got your design. Appreciate it

    Reply
  13. Wayfair

    Heya i am for the primary time here. I came
    across this board and I to find It really helpful & it helped me out much.
    I am hoping to provide something back and aid others like you aided me.

    Reply
  14. Walmart

    I don’t know whether it’s just me or if everybody else experiencing problems with your site.
    It looks like some of the text in your content are running
    off the screen. Can somebody else please comment and let me know if this is happening to them too?
    This may be a issue with my internet browser because
    I’ve had this happen previously. Appreciate it

    Reply
  15. MALWARE

    What’s Going down i am new to this, I stumbled upon this I have found It absolutely useful and it has helped me out loads.

    I am hoping to give a contribution & aid other customers
    like its aided me. Good job.

    Reply
  16. clickme

    After I initially left a comment I seem to have clicked on the -Notify me
    when new comments are added- checkbox and now
    each time a comment is added I get four emails with the exact
    same comment. There has to be an easy method you can remove me from that
    service? Thanks!

    Reply
  17. Ceramic Dinner Set

    Pretty section of content. I just stumbled upon your weblog and in accession capital to
    assert that I get actually enjoyed account your blog posts.

    Anyway I’ll be subscribing to your augment and even I achievement you access consistently fast.

    Reply
  18. MALWARE

    Do you mind if I quote a few of your posts as long as
    I provide credit and sources back to your weblog?
    My blog site is in the very same area of interest as
    yours and my users would genuinely benefit from some of the information you provide here.
    Please let me know if this alright with you. Regards!

    Reply
  19. website

    I’m gone to convey my little brother, that he should also
    pay a quick visit this webpage on regular basis to obtain updated from latest information.

    Reply

Leave a Reply

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