Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:帮我看看!我用的是动态规划!任何数据都能过!但提交就是runtime error!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; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator