Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:这是个约瑟夫问题

Posted by 810974380 at 2009-08-19 09:34:48 on Problem 3629
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator