| ||||||||||
| 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:终于不打表AC,282ms,放出代码,求更快的解法……In Reply To:终于不打表AC,282ms,放出代码,求更快的解法…… Posted by:alexneko at 2008-07-12 16:14:45 > #include <stdio.h>
>
> /*#include <time.h>*/
>
> #include <string.h>
>
>
>
> int main()
>
> {
>
> int arr[15];
>
> memset(arr,0,15*sizeof(int));
>
> while(1)
>
> {
>
> int k,m=0;
>
> scanf("%d",&k);
>
> if(k==0)break;
>
>
> if(arr[k]==0)
>
> {
>
>
>
> while(1)
>
> {
>
> m++;
>
> int bad=k*2,now=0;
>
>
> while(1)
>
> {
>
> now=(now+m-1)%bad+1;
>
> if(now>k)
>
> {
>
> bad--;
>
> now--;
>
> }
>
> else
>
> break;
>
> }
>
>
> if(bad==k){arr[k]=m;break;}
>
> }
>
> }
>
>
> printf("%d\n",arr[k]);
>
>
>
> }
>
> /*printf("%f\n",(float)clock()/CLOCKS_PER_SEC);*/
>
> }
知道位置公式,可不可以倒推?最后位置一定为m+1
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator