Uva 729 - The Hamming Distance Problem
| The Hamming Distance Problem |
题目链接:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=670
今天做的这三题都差不多,还是位运算的问题呵!
1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 6 int main() 7 { 8 9 int T = 0, list[20]; 10 cin>>T; 11 for(int k=1; k<=T; ++k) 12 { 13 int n, h; 14 cin>>n>>h; 15 for(int i=0; i<(1<<n); ++i) 16 { 17 int num = 0; 18 int cnt = 0; 19 for(int j=0; j<n; ++j) 20 if(i&(1<<j)) num++; 21 if(num == h) 22 { 23 int temp = i; 24 int list[20]; 25 memset(list, 0, sizeof(list)); 26 for(int t=1; t<=n; ++t) 27 { 28 list[t-1] = temp%2; 29 temp = temp/2; 30 } 31 for(int t=n; t>=1; --t) 32 cout<<list[t-1]; 33 cout<<endl; 34 } 35 } 36 if(k != T) cout<<endl; 37 } 38 return 0; 39 }
更多内容请关注个人微信公众号 物役记 (微信号:materialchains)
作者:雪影蓝枫
本文版权归作者和博客园共有,欢迎转载,未经作者同意须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。


浙公网安备 33010602011771号