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

类似冒泡程序

Posted by csujk at 2008-06-09 13:38:12 on Problem 1455
//类似冒泡程序
//如果所有人是线性排列,那我们的工作就是类似冒泡程序做的工作:1,2,3,4,5变为5,4,3,2,1 ,耗时n(n-1)/2
//但是出现了环,也就是说1,2,3,4,5变为3,2,1,5,4也可满足条件  
//我们可以把这个环等分成两个部分 ,每个部分看成是线性的,再把它们花的时间加起来.
//当n是偶数时, 每份人数n/2 ,即 2*(n/2 -1 +1)*(n/2 -1)/2;
//当n是奇数时,两份的人数分别是n/2和n/2+1,即(n/2 -1 +1)*(n/2 -1)/2 + (n/2 +1)*(n/2)/2 ;

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