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:大家快来看看! 这个题不就是UVA的120吗 怎么我在这里就是过不了呢? 大家帮帮我啊!In Reply To:Re:大家快来看看! 这个题不就是UVA的120吗 怎么我在这里就是过不了呢? 大家帮帮我啊! Posted by:testSky at 2007-08-13 11:05:06 附代码: #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int num=35; int a[num],result[num],n,c; bool input(){ scanf("%d",&n); if(n==0){ return false; } for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } c=1; return true; } /* void flip(int length){ int i,tmp; for(i=1;i<=length/2;i++){ tmp=a[i]; a[i]=a[length-i+1]; a[length-i+1]=tmp; } } */ void compute(){ int i,j,k,l; for(l=n;l>0;l--){ for(i=1;i<=n&&a[i]!=l;i++); if(i!=l){ if(i!=1){ reverse(&a[1],&a[i+1]); result[c++]=i; } reverse(&a[1],&a[l+1]); result[c++]=l; } } } void show(){ printf("%d",c-1); for(int i=1;i<c;i++){ printf(" %d",result[i]); } putchar('\n'); } int main(){ while(input()){ compute(); show(); } system("PAUSE"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator