#include <iostream> #include <cstring> using namespace std; int main(){ int count = 0; int input[101] = {0}; int N; while(cin >> N){ for(int i = 0; i < N; ++i) cin >> input[i]; bool legal = true; bool repeat[20002] = {false}; for(int i = 0; i < N && legal; ++i) for(int j = i; j < N; ++j){ int sum = input[i] + input[j]; if(repeat[sum]){ legal = false; break; }else{ repeat[sum] = true; } } cout << "Case #" << ++count << ": It is " << (legal ? "" : "not ") << "a B2-Sequence." << endl << endl; } return 0; }
#include #include using namespace std; int main(){ int count = 0; int input[101] = {0}; int N; while(cin >> N){ for(int i = 0; i < N; ++i) cin >> input[i]; bool legal = true; bool repeat[20002] = {false}; for(int i = 0; i < N && legal; ++i) <----ERROR !!! (N-->N-1) for(int j = i; j < N; ++j){ <----ERROR !!! (i-->i+1) int sum = input[i] + input[j]; printf("input[i]=%d input[j]=%d sum=%d\n", input[i], input[j], sum); <----TEST if(repeat[sum]){ legal = false; break; }else{ repeat[sum] = true; } } cout << "Case #" << ++count << ": It is " << (legal ? "" : "not ") << "a B2-Sequence." << endl << endl; } return 0; }
這個程式可以AC,但卻是有錯誤的
例如:
4
1 2 3 8
應該是 B2 才對!
#include #include using namespace std; int main(){ int count = 0; int input[101] = {0}; int N; while(cin >> N){ for(int i = 0; i < N; ++i) cin >> input[i]; bool legal = true; bool repeat[20002] = {false}; for(int i = 0; i < N && legal; ++i) N-1) for(int j = i; j < N; ++j){ i+1) int sum = input[i] + input[j]; printf("input[i]=%d input[j]=%d sum=%d\n", input[i], input[j], sum); if(repeat[sum]){ legal = false; break; }else{ repeat[sum] = true; } } cout << "Case #" << ++count << ": It is " << (legal ? "" : "not ") << "a B2-Sequence." << endl << endl; } return 0; }
這個程式可以AC,但卻是有錯誤的
例如:
4
1 2 3 8
應該是 B2 才對!
並沒有喔。題目裡的 i 是可以等於 j 的。
因此1、2、3、8會生成出以下數字:
2、3、4、9、4、5、10、6、11、16,數字4重複了,因此不是 B2 sequence