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 |
别人爆搜0MS,偶又潮湿,可见代码多烂 - -这T考什么呢?总不能是STL!潮湿的先放着,搞STL去了#include<iostream> #include<algorithm> using namespace std; const int nax=20; int mm[nax],t[nax]; void Levin_walk(int n,int k) { int i; int ter,tmp;//ter记录从左到右找到的满足他小于相邻右边数字的数,tmp记录ter右边大于ter且与其差值最小 while(k--) { ter=tmp=0; for(i=n;i>0;i--) if(mm[i]>mm[i-1]) { ter=i-1; break; } if(ter) { for(i=ter+1;i<=n;++i) if(mm[ter]<mm[i] && mm[tmp]>mm[i]) tmp=i; mm[tmp]^=mm[ter]; mm[ter]^=mm[tmp]; mm[tmp]^=mm[ter]; } sort(mm+ter+1,mm+n+1); } } int summ(int a[],int b[],int k) { int kk=0; int i; if(1==k) return b[1]; for(i=1;i<k;++i) b[++kk]=a[i]+a[i+1]; summ(b,b,kk); return b[1]; } int main() { int n,sum,i; scanf("%d%d",&n,&sum); for(i=1;i<=n;++i) mm[i]=i; mm[0]=1<<25; //int coun=1; while(true) { //int kk; if(summ(mm,t,n)==sum) goto output; Levin_walk(n,1); } output: for(i=1;i<=n;++i) printf("%d ",mm[i]); return false; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator