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

1A水过。。。。。给不会的一点提示吧

Posted by bellxtq at 2013-11-22 19:41:47 on Problem 1680
因为父进程不会打印Process那句,所以只要反过来递归子进程之前先打印了这句,子进程就能从loop开始了
诶,语文太差,感觉没说清楚,直接贴代码吧

#include <stdio.h>
int n,k,id;
int dfs(int A,int loop)
{
	int i=loop,_id=id++;
	for(;i<n;++i)
	{
		if(0 == --k)
		{
			printf("Loop %d: Process ID=%d\n",i,_id);
			return 1;
		}
		A+=7;
		if(0 == --k)
		{
			printf("Process ID=%d, A=%d\n",id,A);
			return 1;
		}
		if(1 == dfs(A,i+1))
		{
			return 1;
		}
	}
	return 0;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d %d",&n,&k);
		id=1000;
		dfs(0,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