| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:高手指点:怎样改才不超时,郁闷中.......In Reply To:高手指点:怎样改才不超时,郁闷中....... Posted by:jinweiliang at 2009-04-05 15:56:25 > // 1833.cpp : Defines the entry point for the console application.
> //
>
> //#include "stdafx.h"
> #include <stdio.h>
>
>
> #include<algorithm>
> using namespace std;
>
> int main()
> {
> int m;
> //freopen("1833.txt","r",stdin);
>
> scanf("%d",&m);
> while(m--)
> {
> int n,j,k,i,a[1025];
> scanf("%d %d",&n,&k);
> for(i=0;i<n;i++)
> {
> scanf("%d",&a[i]);
> //printf("%d",a[i]);
> }//printf("\n");
>
> i=0;
> j=1;
> while(1)
> {
> if(!next_permutation(a,a+n))//产生当前排列的后一个排列
> {
> for(i=1;i<n;i++)
> printf("%d ",i);
> printf("%d\n",i);
> goto loop;
> }
> else if(next_permutation(a,a+n))
> {
> j++;
> if(j==k)
> {
> for(i=0;i<n-1;i++)
> printf("%d ",a[i]);
> printf("%d\n",a[i]);
> goto p2;
> }
> }
> }
> p2:;
> loop:;
>
> }
> return 0;
> }
>
直接用 next_permutation() K次就可以了呀~~
for(i=0;i<k;i++)
{
next_permutation(p,p+n);
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator