题目: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 901题目: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 811题目:http://uva.onlinejudge.org/i ... -
UVa 216 Getting in Line
2012-08-29 20:48 724题目:http://uva.onlinejudge.org/i ... -
UVa 10474 Where is the Marble?
2012-08-28 13:45 851题目:http://uva.onlinejudge.org/i ... -
UVa 592 Island of Logic
2012-08-27 11:05 1640题目:http://uva.onlinejudge ... -
UVa 11205 The broken pedometer
2012-08-25 17:28 1049题目:http://uva.onlinejudge.org/i ... -
UVa 131 The Psychic Poker Player
2012-08-24 22:28 874题目:http://uva.onlinejudge.org/i ... -
Uva 10098 Generating Fast
2012-08-23 15:28 659题目:http://uva.onlinejudge.org/i ... -
UVa 146 ID Codes
2012-08-20 18:46 763题目:http://uva.onlinejudge.org/i ... -
UVa 10167 Birthday Cake
2012-08-16 20:57 604题目:http://uva.onlinejudge.org/i ... -
UVa 10129 Play on Words
2012-08-15 22:49 1126题目:http://uva.onlinejudge.org/i ... -
UVa 10596 Morning Walk
2012-08-14 22:05 879题目:http://uva.onlinejudge.org/i ... -
Uva 10305 Ordering Tasks
2012-08-13 23:40 658题目:http://uva.onlinejudge.org/i ... -
Uva 10004 Bicoloring
2012-08-13 23:34 874题目:http://uva.onlinejudge.org/i ... -
Uva 532 Dungeon Master
2012-08-13 23:29 787题目:http://uva.onlinejudge ... -
Uva 439 Knight Moves
2012-08-11 22:24 656题目:http://uva.onlinejudge.org/i ... -
UVa 784 Maze Exploration
2012-08-11 14:09 825题目:http://uva.onlinejudge.org/i ... -
Uva 572 Oil Deposits
2012-08-11 11:43 745题目:http://uva.onlinejudge.org/i ...
相关推荐
动态规划 Hamming Problem 解题报告
iris recognition code matlab + iris code + code matlab for iris recognition + hamming distance code matlab
Tool to measure code distance using Number Geometry
通过此代码可以检索利用算法筛选出来的DNA序列是否满足汉明距离、GC含量等约束条件。
基于视觉词和海明距离优化机制的相似图片检索系统的研究,庄煌,魏翼飞,图片相似检索是通过输入一张查询图,在数据库中基于内容的“语义”,检索出和输入图片相似的图片。本文提出了一种新颖的方法,用于基
该文献的主要思想是:输入文件的哈希值(我用的是文件名)例如一个64位的哈希值,多次随机抽取若干位(例如4位)的值组成一个字串,按照字串值的不同将文件放入不同的哈希桶中。这样一个64位哈希值将被放入64/4=16个...
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 between codewords correlates with semantic similarity. In this paper, we show that the problem of finding a best code for a given dataset is closely related to the problem of graph ...
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 code in matlab
cpu(Hamming码)
Hamming distance, Hamming spheres and error correcting capability
For implementing the Hamming coding in verilog or VHDL
74Hamming code in Gaussian channel
Hamming法求级数,级数,x取值点,误差范围皆在程序中指定,C语言
hamming 级数求和 精度可以控制 比较暴力 高精度需要考虑n溢出问题