USACO--2.1Hamming Codes
2015-03-13 12:35
330 查看
开始的时候没有什么思路,后面看了一下数据范围不大,直接就暴力了。
其实我们只需要从题目中给定的0–2^B-1这些数中从小到大选n个出来就行了,只需要满足每次选择的数和前面已选的数的Hamming距离必须不小于D。
代码如下:
其实我们只需要从题目中给定的0–2^B-1这些数中从小到大选n个出来就行了,只需要满足每次选择的数和前面已选的数的Hamming距离必须不小于D。
代码如下:
/* ID: 15674811 LANG: C++ TASK: hamming */ #include<iostream> #include<cstdio> #include<cstring> #include<fstream> using namespace std; int n,B,D,cnt,ans[100]; bool check(int x) { for(int i=1;i<cnt;i++) { int c=0; for(int d=0;d<B;d++) if(((1<<d)&x)!=((1<<d)&ans[i])) c++; if(c<D) return false; } return true; } int main() { ofstream fout("hamming.out"); ifstream fin("hamming.in"); //ifstream fin("lkl.txt"); while(fin>>n>>B>>D) { cnt=1; int k=(1<<B)-1; for(int i=0;i<=k;i++) { if(check(i)) ans[cnt++]=i; if(cnt>n) break; } for(int i=1;i<cnt;i++) { fout<<ans[i]; if((i!=0&&i%10==0)||(i==n)) fout<<endl; else fout<<" "; } } return 0; }
相关文章推荐
- usaco Hamming Codes
- USACO Hamming Codes 求汉明距离
- USACO :Hamming Codes 解题报告
- USACO Hamming Codes 2.1
- USACO Hamming Codes DFS 构造
- USACO-Section2.1 Hamming Codes [搜索]
- usaco2.14Hamming Codes
- USACO Section 2.1 Hamming Codes - 题意相当坑爹..很无聊..
- USACO Hamming Codes
- 2.1Hamming Codes
- 从usaco hamming Codes谈FP思想及FP技巧
- USACO Hamming Codes
- usaco 2008 January Telephone Lines 架设电话线 题解
- poj 3659 Cell Phone Network USACO 树形DP
- bzoj1774 [Usaco2009 Dec]Toll 过路费
- usaco 1.4 The Clocks(暴搜)and poj 1166
- USACO 2010 Mar Gold 1.Great Cow Gathering 树形dp
- 1617: [Usaco2008 Mar]River Crossing渡河问题
- 题解:[USACO 3.2] 香甜的黄油
- 【USACO题库】4.2.1 Drainage Ditches草地排水