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:Re:这是个约瑟夫问题 Posted by:yulewei at 2008-07-10 10:08:38 > 直接模拟~~~ #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int a[2000000],b[80000]; int n,k,p; int main() { int sign,end,num,length,i,j,l; scanf("%d %d %d",&n,&k,&p); for(i=0;i<k;i++) a[i]=(i+1); sign=0;end=k-1;num=0;length=0; while(num!=k) { num++; if(num%n==0) b[length++]=a[sign]; for(j=sign+1;j<=sign+p;j++) a[end+j-sign]=a[j]; sign+=p+1; end+=p; } sort(b,b+length); for(l=0;l<length;l++) printf("%d\n",b[l]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator