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:帮我看看!我用的是动态规划!任何数据都能过!但提交就是runtime error!

Posted by ling2ling2 at 2009-04-10 18:34:08 on Problem 3278
In Reply To:帮我看看!我用的是动态规划!任何数据都能过!但提交就是runtime error! Posted by:li4951 at 2009-03-22 21:15:13
> #include<iostream>
> #include<cmath>
> using namespace std;
> 
> bool cal(int a, int b)
> {
> 	if(a == b)
> 	{
> 		return 1;
> 	}
> 	else
> 		return 0;
> }
> 
> int main()
> {
> 	int n = 5;
> 	int k = 17;
> 	cin >> n >> k;
> 	int i = 0;
> 	int data[10000] = {0};
> 	int sdata[10000] = {0};
> 	sdata[1] = n;
> 	int answer = 0;
> 	int sign = 0;
> 	if(n == k)
> 	{
> 		cout << "0" << endl;
> 	}
> 	else
> 	{
> 		for(i = 1,answer = 1; ; i = i * 3,answer++)
> 		{
> 			int t = pow(3.0, answer - 1);
> 			int j = 0;
> 		
> 			for(j = 1; j <= t; j++)
> 			{
> 				int p = sdata[j];
> 				int m = (j - 1) * 3 + 1;
> 				data[m] = p - 1;
> 				data[m + 1] = p + 1;
> 				data[m + 2] = p * 2;
> 				if(cal(data[m], k) || cal(data[m + 1], k) || cal(data[m + 2], k))
> 				{
> 					sign = 1;
> 					break;
> 				}
> 			}
> 			if(sign == 1)
> 			{
> 				cout << answer << endl;
> 				break;
> 			}
> 			for(j = 1; j <= t * 3; j++)
> 			{
> 				sdata[j] = data[j];
> 			}
> 		}
> 	}
> 	return 0;
> }



10000肯定不够

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