zoukankan      html  css  js  c++  java
  • USACO Section 2.1 Hamming Codes

    暴力

     1 /* ID:linyvxi1
    2 PROB:hamming
    3 LANG:C++
    4 */
    5 #include <stdio.h>
    6 #include <math.h>
    7 #include <stdlib.h>
    8 int N,B,D;
    9 int max_search_num;
    10 int final_result[130];
    11 int num_found;
    12
    13 bool check(int next)
    14 {
    15 int s=0;
    16 for(;s<num_found;s++){
    17 int temp;
    18 temp=next^final_result[s];
    19 int count=0;
    20 int i;
    21 for(i=0;i<B;i++){
    22 int out_num=temp&0x00000001;
    23 if(out_num){
    24 count++;
    25 }
    26 temp=temp>>1;
    27 }
    28 if(count<D){
    29 return false;
    30 }
    31 }
    32 return true;
    33 }
    34 int main()
    35 {
    36 freopen("hamming.in","r",stdin);
    37 freopen("hamming.out","w",stdout);
    38 scanf("%d%d%d",&N,&B,&D);
    39 max_search_num=(int)pow(2,B)-1;
    40 final_result[0]=0;
    41 int i;
    42 num_found=1;
    43 for(i=1;i<=max_search_num;i++){
    44 if(num_found==N){
    45 break;
    46 }
    47 if(check(i)){//如果hamming距离符合要求
    48 final_result[num_found++]=i;
    49 }
    50 }
    51 int already_output=0;
    52 for(i=0;i<num_found;i++){
    53 printf("%d",final_result[i]);
    54 already_output++;
    55 if(already_output%10==0){
    56 putchar('\n');
    57 }else if(i!=num_found-1){
    58 putchar(' ');
    59 }else{
    60 putchar('\n');
    61 }
    62 }
    63 }



  • 相关阅读:
    生产者消费者模型
    查看网络通不通的几种方法
    tomcat在45秒内没有启动,启动超时
    request获取各种路径
    修改web项目发布路径
    web.xml不同版本的头
    Web.xml 错误或异常页面配置
    ModelAndView command
    java初始化顺序
    初始化时的过程
  • 原文地址:https://www.cnblogs.com/yangce/p/2382533.html
Copyright © 2011-2022 走看看