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 frkstyc at 2005-03-07 17:50:25 on Problem 1012
int main(void)
{
	int k;
	for(;;)
	{
		scanf("%d", &k);
		if(k == 0)
		{
			break;
		}
		__asm
		{
			mov edi, dword ptr [k]
			mov ebx, edi
			shl edi, 1
		_OLoop:
			mov ecx, edi
			mov eax, ebx
			xor edx, edx
			dec eax
			div ecx
			mov eax, edx
		_ILoop:
			mov edx, edi
			shr edx, 1
			cmp eax, edx
			jge _2ndBranch
		_1stBranch:
			cmp ecx, edx
			je _Found
			inc ebx
			jmp _OLoop
		_2ndBranch:
			dec ecx
			dec eax
		_AfterBranches:
			add eax, ebx
			xor edx, edx
			div ecx
			mov eax, edx
			jmp _ILoop
		_Found:
			mov dword ptr [k], ebx
		}
		printf("%d\n", k);
	}
}

汇编那段相当于
(ecx = n, ebx = m, eax = i, edi = k*2)
int m, f = 0;
for(m = k; f == 0; m++)
{
	int n = k;
	int i;
	for(i = (m - 1) % n; ; i = (i + m) % n)
	{
		if(i < k >> 1)
		{
			if(n == k >> 1)
			{
				f = 1;
			}
			break;
		}
		else
		{
			n--;
			i--;
		}
	}
}

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