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:还以为用next_permutation,邪恶了 Posted by:407811696 at 2011-04-12 21:43:24 #include <iostream> #include <cstdio> using namespace std; int a[50005]; int n,m; int main() { // freopen("1.txt","r",stdin); while(scanf("%d%d",&n,&m),!(n==-1&&m==-1)) { int i,j,k,p; for(i=1;i<=n;i++) a[i]=i; if(m!=0) { for(i=0;m;) { if(m>i+1) { i++; m-=i; } else { i++; break; } } k=n-i+m; for(j=n-i,p=n;j<=n;j++) { if(k!=j) a[p--]=j; } a[p]=k; } for(i=1;i<=n;i++) { if(i!=1) printf(" "); printf("%d",a[i]); } printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator