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 |
just use scanf("%e"/"%f"/"%g")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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator