【 OJ 】 HDOJ1021 18年10月31日19:27 [ 20 ]

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/QingCoffe/article/details/83589197

开局直接WA了

代码如图:

# include<iostream>
using namespace std;
int Feibo[1000000] = {7,11};
bool visit[1000000];
// F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
int Fibonacci(int n) {
	if (visit[n])
		return Feibo[n];
	else {
		Feibo[n] = Fibonacci(n - 1) + Fibonacci(n - 2);
		visit[n] = 1;
	}
	return Feibo[n];
}//此代码估计超时
int main(void) {
	int n;
	while (cin >> n) {
		memset(visit, 0, sizeof(visit));
		visit[0] = 1;
		visit[1] = 1;
		if (!(Fibonacci(n) % 3))
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	system("pause");
	return 0;
}

后来看了别人的代码,发现是找规律......

# include<iostream>
using namespace std;
int main(void) {
	int n;
	while (cin >> n) {
		if (n % 8 == 2 || n % 8 == 6)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/QingCoffe/article/details/83589197