USACO 2.1 Hamming Codes (hamming)
来源:互联网 发布:c语言输入n个数比大小 编辑:程序博客网 时间:2024/05/16 12:47
//Main Idea//We use the greedy algorithm and start to check the hamming distance of nummber from//the minimun num.The pity is that I can't prove the correctness of it.I will try it later./*ID: haolink1PROG: hammingLANG: C++*///#include <iostream>#include <fstream>#include <vector>using namespace std;short bit_num= 0;short min_distance = 0 ;short CountDistance(short element1,short element2);bool CheckValid(vector<short>& selected_codewords,short codeword);int main(){ ifstream fin("hamming.in"); short codewords_num = 0; fin >> codewords_num >> bit_num >> min_distance; short max_value = (1 << bit_num);// for(short i = 0; i < bit_num; i++){// max_value *= 2;// } vector<short> selected_codewords; // 0 can be one of the numbers in the set, because if the minimum number in the set // were N instead of 0, we could XOR N to each number in the set and they would //still be the same distance apart. selected_codewords.push_back(0); //Note the counter start form 1; short counter = 1; //Start from minimun number; for(short i = 1; i <= max_value; i++){ if(CheckValid(selected_codewords,i)){ selected_codewords.push_back(i); counter++; } if(counter >= codewords_num) break; } ofstream fout("hamming.out"); //Note the ouput format; short print_num = 0; short len = selected_codewords.size(); for(short i = 0; i < len-1; i++){ if(print_num < 9){ fout<<selected_codewords[i]<<" "; print_num++; }else{ fout<<selected_codewords[i]<<endl; print_num = 0; } } if(len > 0) fout<<selected_codewords[len-1]<<endl; return 0;}short CountDistance(short element1,short element2){ short distance = 0; short diff = element1 ^ element2; for(short i = 0; i < bit_num; i++){ if((1<<i)& diff) distance++; } return distance;}bool CheckValid(vector<short>& selected_codewords,short codeword){ for(short i = 0; i < short(selected_codewords.size());i++){ if(CountDistance(selected_codewords[i],codeword) < min_distance) return false; } return true;}
0 0
- USACO 2.1 Hamming Codes (hamming)
- USACO--2.1Hamming Codes
- USACO 2.1 Hamming Codes
- USACO 2.1 Hamming Codes
- USACO Hamming Codes 2.1
- USACO 2.1.5 Hamming Codes
- [USACO 2.1.5] Hamming Codes
- usaco 2.1.5 Hamming Codes
- USACO 2.1.5 Hamming Codes
- USACO Section 2.1 Hamming Codes
- USACO Section 2.1 Hamming Codes
- USACO 2.1 Hamming Codes (递归)
- USACO 2.1.5 Hamming Codes
- 【搜索】【USACO】Hamming Codes
- usaco training-Hamming Codes
- usaco Hamming Codes
- USACO:Hamming Codes
- USACO-Hamming Codes
- 行内元素浮动变成成块状元素了,就可以加宽和高了。例如a标记
- WebForm 基础3 ViewState
- Git_Windows 系统下Git安装图解
- Levenshtein算法
- Git操作指南(2) —— Git Gui for Windows的建库、克隆(clone)、上传(push)、下载(pull)、合并
- USACO 2.1 Hamming Codes (hamming)
- requestWindowFeature的几个值
- Jsp学习笔记以及相关总结积累
- 只要我还有呼吸,我就想你!
- 国家集训队论文分类整理
- USACO 2.2 Preface Numbering (preface)
- 与KineticJS HTML5画布上跳跃的兔子
- Unity学习(三):Unity中的一些基本概念
- 黑马程序员---基础强化---反射