USACO 2.1 Hamming Codes
Hamming Codes
Rob Kolstad
Given N, B, and D: Find a set of N codewords (1 <= N <= 64), each of length B bits (1 <= B <= 8), such that each of the codewords is at least Hamming distance of D (1 <= D <= 7) away from each of the other codewords. The Hamming distance between a pair of codewords is the number of binary bits that differ in their binary notation. Consider the two codewords 0x554 and 0x234 and their differences (0x554 means the hexadecimal number with hex digits 5, 5, and 4):
0x554 = 0101 0101 0100
0x234 = 0010 0011 0100
Bit differences: xxx xx
Since five bits were different, the Hamming distance is 5.
PROGRAM NAME: hamming
INPUT FORMAT
N, B, D on a single line
SAMPLE INPUT (file hamming.in)
16 7 3
OUTPUT FORMAT
N codewords, sorted, in decimal, ten per line. In the case of multiple solutions, your program should output the solution which, if interpreted as a base 2^B integer, would have the least value.
SAMPLE OUTPUT (file hamming.out)
0 7 25 30 42 45 51 52 75 76
82 85 97 102 120 127 题目大意:就是给你NBD三个正整数,意思是在0到2^B-1中选择N个数字,而且两两之间“距离”大于D。对“距离”是这么定义的,二进制对应位不同符号的个数。
思路:说实话是没有什么思路的,有想搜索但是好虚,觉得数据不小(选或者不选,复杂度是2^(2^B-1)),不敢写,后来上网看了解析,居然就是搜索,还是最裸的那种。。。有点想不明白,不过也提醒我,撑死胆大的,饿死胆小的。代码如下
/*
ID:fffgrdc1
PROB:hamming
LANG:C++
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
using namespace std;
int n,m,d,cnt=;
int topnum=;
int ans[]={};
bool check(int x,int y)
{
x=x^y;int tot=;
while(x)
{
if(x&)tot++;
x>>=;
}
return tot>=d;
}
void dfs(int x)
{
if(cnt==n)
{
int num=;
for(int i=;i<=cnt;i++)
{
num++;
if(num==)
printf("%d",ans[i]);
else printf(" %d",ans[i]);
if(num==)
{
printf("\n");
num=;
}
}
if(num)printf("\n");
exit();
}
if(x>topnum)return;
int flag=;
for(int i=;i<=cnt;i++)
{
if(!check(ans[i],x))
{
flag=;
break;
}
}
if(flag)
{
ans[++cnt]=x;
dfs(x+);
cnt--;
}
dfs(x+); }
int main()
{
freopen("hamming.in","r",stdin);
freopen("hamming.out","w",stdout);
scanf("%d%d%d",&n,&m,&d);
while(m--)topnum<<=;
topnum--;
//printf("%d\n",topnum);
dfs();
return ;
}
USACO 2.1 Hamming Codes的更多相关文章
- USACO Section2.1 Hamming Codes 解题报告 【icedream61】
hamming解题报告----------------------------------------------------------------------------------------- ...
- 洛谷P1461 海明码 Hamming Codes
P1461 海明码 Hamming Codes 98通过 120提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 给出 N,B 和 ...
- 洛谷 P1461 海明码 Hamming Codes
P1461 海明码 Hamming Codes 题目描述 给出 N,B 和 D,要求找出 N 个由0或1组成的编码(1 <= N <= 64),每个编码有 B 位(1 <= B &l ...
- 【USACO 2.1】Hamming Codes
/* TASK: hamming LANG: C++ URL:http://train.usaco.org/usacoprob2?a=5FomsUyB0cP&S=hamming SOLVE: ...
- USACO Hamming Codes DFS 构造
我还是用了很朴素的暴力匹配A了这题,不得不感叹USACO时间放的好宽... /* ID: wushuai2 PROG: hamming LANG: C++ */ //#pragma comment(l ...
- USACO 2.1 海明码 Hamming Codes (模拟+位运算+黑科技__builtin_popcount(n))
题目描述 给出 N,B 和 D,要求找出 N 个由0或1组成的编码(1 <= N <= 64),每个编码有 B 位(1 <= B <= 8),使得两两编码之间至少有 D 个单位 ...
- USACO Section 2.1: Hamming Codes
挺简单的一道题 /* ID: yingzho1 LANG: C++ TASK: hamming */ #include <iostream> #include <fstream> ...
- USACO Hamming Codes
题目大意:求n个两两hamming距离大于等于d的序列,每个元素是一个b bit的数 思路:仍然暴力大法好 /*{ ID:a4298442 PROB:hamming LANG:C++ } */ #in ...
- P1461 海明码 Hamming Codes
题目描述 给出 N,B 和 D,要求找出 N 个由0或1组成的编码(1 <= N <= 64),每个编码有 B 位(1 <= B <= 8),使得两两编码之间至少有 D 个单位 ...
随机推荐
- 带中横线的日期格式在iOS手机系统上 转换时间戳NaN问题
类似于 '2019-04-01 14:13:00' 这样的日期格式转换时间戳在iOS手机上是无法转换的,需要先处理日期格式成 '2019/04/01 14:13:00' var str = '2019 ...
- 3、Collection接口中的功能概述
package cn.itcast_01; import java.util.ArrayList; import java.util.Collection; /** * 集合: * 由于我们使用的是面 ...
- 问题集锦 ~ CSS
#button标签点击后出现点边框 input {outline: none;} button::-moz-focus-inner {border: none;}
- Oracle数据库安装与连接与简介
Oracle数据库的安装 1.登录Oracle官网——试用和下载 2.同意协议--->file1 3.完成配置 4.测试连接:打开Oracle developer--->新建连接,注意用户 ...
- Qt:&OpenCV—Q图像处理基本操作(Code)
原文链接:http://www.cnblogs.com/emouse/archive/2013/03/31/2991333.html 作者写作一系列:http://www.cnblogs.com/em ...
- 模拟试题C
模拟试题C 一.单项选择题(2′*14 =28′) 1.双线性法向插值法(Phong Shading)的优点是( ) A)法向计算精确 B)高光域准确 C)对光源和视点没有限制 D)速度较快 2.用编 ...
- Rx (Reactive Extensions)介绍
Reactive Extensions (Rx) 原来是由微软提出的一个综合了异步和基于事件驱动编程的库包,使用可观察序列和LINQ-style查询操作. 使用Rx, 开发者可以用Observable ...
- sql语句参数化问题
select @PageSize * from tets SELECT 在WHERE 之前都不能参数化. TOP 只能做字符串运行.
- ZooKeeper伪集群的搭建(Windows)
首先下载 zookeeper 地址:https://www.apache.org/dyn/closer.cgi/zookeeper/ 1.下载完成解压后修改文件夹名字为zookeeper1,然后删除c ...
- 让SSL证书给服务器上一把“锁”
近期,用户数据泄露的新闻接二连三地被曝光.先有京东金融App涉嫌自动获取用户手机中的敏感照片,随后CNET又爆出中国深圳的一家人工智能公司深网视界对于其人脸识别数据库没有密码保护,导致250万用户信息 ...