| ||||||||||
| 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 | |||||||||
内存的计算不仅仅和你定义的变量有关,还和你使用的操作有关,注意使用移位操作会比乘法操作快,取模操作尽量少用In Reply To:跪求各位大牛,那些20K左右memory的C/C++是怎么做的? Posted by:xiao1590 at 2007-02-19 22:53:46 内存的计算不仅仅和你定义的变量有关,还和你使用的操作有关,注意使用移位操作会比乘法操作快,取模操作尽量少用。看下面这个代码就满足你说的要求
#include <stdio.h>
int main()
{
int n,a,i;
while(scanf("%d",&n)!=-1)
{
for (i=1,a=1;a;i++)
{
a=(a<<3)+(a<<1);
a++;
a%=n;
}
printf("%d\n",i);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator