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

Re:我想用递归来解,感觉思路很有意思,可惜不知道哪里出错了哦~~请大侠们帮帮忙(附代码)

Posted by ecjtuzhengyq at 2007-07-20 11:39:14 on Problem 2081
In Reply To:我想用递归来解,感觉思路很有意思,可惜不知道哪里出错了哦~~请大侠们帮帮忙(附代码) Posted by:304988557 at 2006-09-13 18:29:45
> #include<iostream.h>
> #include<string.h>
> #include <stdio.h>
> #include<math.h>
> int i,t,temp,a;
> int test(int k)
> {
> 	if(k==0) return 0;
> 	else
> 	{
> 		a=test(k-1);
> 		t=a-k;
> 		if(t>0)
> 		{
> 			temp=1;
> 			for(i=0;i<k;i++)
> 			{
> 				if(test(i)==t)
> 				{
> 					temp=0;
> 					break;
> 				}
> 
> 				
> 			}
> 			if(temp==1) return t;
> 				
> 		}
> 
> 		else
> 			return test(k-1)+k;
> 	}
> }
> int main()
> {
>     int num,k;
> 	while(cin>>k)
> 	{
> 		if(k==-1) return 1;
> 	    num=test(k);
> 	    cout<<num<<endl;
> 	}
> 	
>     return 1;
> }

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