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

just use scanf("%e"/"%f"/"%g")

Posted by tzkq at 2010-06-30 11:54:07 on Problem 1781 and last updated at 2010-06-30 11:54:43
In Reply To:读入数据时,可以这样写:scanf("%d\e%d",&N,&E)。这样就不用从字符串中分析数字了。 Posted by:Xiao_Xiao_ at 2010-04-15 16:27:28
必须得找规律? 也可以进行对O(n)的优化。

首先,约瑟夫有O(n)的算法, 其次,在间隔比较短的情况下,一次可以跳多步不影响结果。


int n,i,x,k;
float f;
int main(){
	for(;scanf("%f",&f)&&(n=f+0.1);){
		for(x=i=1;i<=n;i+=k){
			k=(i-x)/2;
			if(n<k+i)k=n-i;
			if(!k)k=1;
			x=(x+2*k)%i;
		}
		printf("%d\n",x+1);
	}
}

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