题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=670
枚举十进制数0~2^N-1,对于每一个数都跟0异或,并把异或的结果转换成二进制,计算二进制数中1的个数,如果等于H,那么把该二进制数输出,注意不要忽略了前导零。
PS:今天才发现,UVa会把格式错误看作是Wrong Answer,不知道是不是所有题目都是这样。
枚举十进制数0~2^N-1,对于每一个数都跟0异或,并把异或的结果转换成二进制,计算二进制数中1的个数,如果等于H,那么把该二进制数输出,注意不要忽略了前导零。
#include<stdio.h> #include<math.h> void solve(int XOR,int N,int H) { int res[20],top=0,cnt=0; while(XOR>0) { int tmp=XOR%2; if(tmp) cnt++; res[++top]=tmp; XOR/=2; } if(cnt==H) { if(top<N) { int t=N-top; while(t--) putchar('0'); } while(top) { printf("%d",res[top]); top--; } putchar('\n'); } } int main() { int i,lim,XOR,T,N,H; scanf("%d",&T); while(T--) { scanf("%d%d",&N,&H); lim=pow(2,N); for(i=0;i<lim;i++) { XOR=i^0; solve(XOR,N,H); } if(T>0) putchar('\n'); } return 0; }
PS:今天才发现,UVa会把格式错误看作是Wrong Answer,不知道是不是所有题目都是这样。
发表评论
-
UVa 10422 Knights in FEN
2012-09-07 08:40 937题目:http://uva.onlinejudge.org/i ... -
UVa 539 The Settlers of Catan
2012-08-31 22:22 28题目:http://uva.onlinejudge.org/i ... -
UVa 301 Transportation
2012-08-31 22:10 34题目:http://uva.onlinejudge.org/i ... -
UVa 639 Don't Get Rooked
2012-08-30 23:01 850题目:http://uva.onlinejudge.org/i ... -
UVa 216 Getting in Line
2012-08-29 20:48 758题目:http://uva.onlinejudge.org/i ... -
UVa 10474 Where is the Marble?
2012-08-28 13:45 883题目:http://uva.onlinejudge.org/i ... -
UVa 592 Island of Logic
2012-08-27 11:05 1679题目:http://uva.onlinejudge ... -
UVa 11205 The broken pedometer
2012-08-25 17:28 1089题目:http://uva.onlinejudge.org/i ... -
UVa 131 The Psychic Poker Player
2012-08-24 22:28 905题目:http://uva.onlinejudge.org/i ... -
Uva 10098 Generating Fast
2012-08-23 15:28 688题目:http://uva.onlinejudge.org/i ... -
UVa 146 ID Codes
2012-08-20 18:46 801题目:http://uva.onlinejudge.org/i ... -
UVa 10167 Birthday Cake
2012-08-16 20:57 634题目:http://uva.onlinejudge.org/i ... -
UVa 10129 Play on Words
2012-08-15 22:49 1180题目:http://uva.onlinejudge.org/i ... -
UVa 10596 Morning Walk
2012-08-14 22:05 920题目:http://uva.onlinejudge.org/i ... -
Uva 10305 Ordering Tasks
2012-08-13 23:40 694题目:http://uva.onlinejudge.org/i ... -
Uva 10004 Bicoloring
2012-08-13 23:34 912题目:http://uva.onlinejudge.org/i ... -
Uva 532 Dungeon Master
2012-08-13 23:29 821题目:http://uva.onlinejudge ... -
Uva 439 Knight Moves
2012-08-11 22:24 691题目:http://uva.onlinejudge.org/i ... -
UVa 784 Maze Exploration
2012-08-11 14:09 881题目:http://uva.onlinejudge.org/i ... -
Uva 572 Oil Deposits
2012-08-11 11:43 788题目:http://uva.onlinejudge.org/i ...
相关推荐
java java_leetcode题解之Hamming Distance.java
iris recognition code matlab + iris code + code matlab for iris recognition + hamming distance code matlab
这个压缩包文件"检验代码_Hammingdistance_GCcontent_DNA_"显然包含了用于检查DNA序列特定属性的程序,具体来说,就是汉明距离(Hamming Distance)和GC含量。下面将详细介绍这两个概念及其在DNA分析中的应用。 **...
在"Hamming Problem"这个编程挑战中,我们需要找到一个特定的Hamming序列中的第i个数。Hamming序列是由三个质数p1, p2, 和 p3定义的,序列包含所有只被这三个质数之一整除的自然数,按递增顺序排列。 例如,给定...
Tool to measure code distance using Number Geometry
c语言入门 c语言_leetcode题解461-hamming-distance.c
Semantic hashing seeks compact binary codes of data-points so that the Hamming distance between codewords correlates with semantic similarity. In this paper, we show that the problem of finding a best...
by the Hamming distance between their respective binary codes. By using two loss functions measuring the degree of divergence between the training and predicted ratings, we formulate the problem of ...
文章的重点是构建一种对抗性强的属性保留哈希函数,用于处理汉明距离(Hamming Distance)谓词。汉明距离衡量的是两个字符串在对应位置上不同字符的数量。该哈希函数可以区分汉明距离至少达到某个阈值t的输入与距离...
We also study two examples of common leakage models: the Hamming weight and the Hamming distance models. For instance, the study in the case of the Hamming weight model gives that the probability of ...
leetcode添加元素使和等于 LeetCodeOne 461. Hamming Distance The Hamming distance between two ...hammingDistance(int x, int y) { int dist = 0; int n = x^y; //异或 while(n) { ++dist; n = n
verilog 实现的hamming码生成,用于fpga
汉明距离(Hamming Distance)和局部敏感哈希(Locality Sensitive Hashing, LSH)是计算机科学中,特别是信息检索和数据挖掘领域里重要的概念。本文将深入探讨这两个概念,以及它们在图像检索中的应用。 首先,...
本实验主题“CPU(Hamming码)”可能是指在CPU设计或模拟过程中,运用Hamming码进行错误检测和纠正。 Hamming码是由Richard W. Hamming于1950年提出的,它通过在原始数据中添加冗余位来实现错误检测和纠正。Hamming...
首先,我们需要理解“Hamming Distance”(哈明距离)和“Locality Sensitive Hashing”(局部敏感哈希,简称LSH)。哈明距离是一种衡量两个等长字符串之间差异的度量,通过计算它们对应位置上不同字符的个数来确定...
汉明码(Hamming Code)是一种纠错编码技术,由理查德·汉明在1950年提出,主要用于检测并纠正数据传输或存储过程中的单个错误位。在MATLAB环境中实现汉明码,可以帮助我们理解其工作原理并进行实际应用。下面将详细...
Hamming法求级数,级数,x取值点,误差范围皆在程序中指定,C语言