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 Toney at 2007-03-12 02:59:55 on Problem 2551
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:
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