【 OJ 】 HDOJ1021 18年10月31日19:27 [ 20 ]
阿新 • • 發佈:2018-12-02
開局直接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;
}