首页 > 代码库 > USACO Section 2.1 Hamming Codes
USACO Section 2.1 Hamming Codes
/* ID: lucien23 PROG: hamming LANG: C++ */ #include <iostream> #include <fstream> #include <vector> using namespace std; int main() { ifstream infile("hamming.in"); ofstream outfile("hamming.out"); if(!infile || !outfile) { cout << "file operation failure!" << endl; return -1; } int N, B, D; infile >> N >> B >> D; vector<int> codewords; int num = 0; codewords.push_back(num); while (codewords.size() < N) { num++; int len = codewords.size(); bool condition = true; for (int i=0; i<len; i++) { int count = 0; for (int j=0; j<B; j++) { int temp = 1 << j; if ((temp&num) != (temp&codewords[i])) { count++; } } if (count < D) { condition = false; break; } } if (condition) { codewords.push_back(num); } } for (int i=0; i<N; i++) { if ((i+1)%10 == 0) { outfile << codewords[i] << endl; } else if (i == N-1) { outfile << codewords[i]; } else { outfile << codewords[i] << " "; } } if (N % 10 != 0) { outfile << endl; } return 0; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。