zoukankan      html  css  js  c++  java
  • USACO hamming 继续暴搜

    USER: Kevin Samuel [kevin_s1]
    TASK: hamming
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.003 secs, 3504 KB]
       Test 2: TEST OK [0.005 secs, 3504 KB]
       Test 3: TEST OK [0.008 secs, 3504 KB]
       Test 4: TEST OK [0.008 secs, 3504 KB]
       Test 5: TEST OK [0.008 secs, 3504 KB]
       Test 6: TEST OK [0.005 secs, 3504 KB]
       Test 7: TEST OK [0.008 secs, 3504 KB]
       Test 8: TEST OK [0.005 secs, 3504 KB]
       Test 9: TEST OK [0.005 secs, 3504 KB]
       Test 10: TEST OK [0.008 secs, 3504 KB]
       Test 11: TEST OK [0.008 secs, 3504 KB]
    
    All tests OK.
    

    YOUR PROGRAM ('hamming') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated

    congratulations.

    /*
    ID:kevin_s1
    PROG:hamming
    LANG:C++
    */
    
    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <vector>
    #include <map>
    #include <set>
    #include <algorithm>
    #include <cstdlib>
    #include <list>
    #include <bitset>
    #include <cmath>
    
    using namespace std;
    
    //gobal variable====
    int N, B, D;
    vector<bitset<8> > result;//bitset能够加速
    string str = "11111111";
    bitset<8> last(str);
    int MaxDeep;
    //==================
    
    
    //function==========
    
    int hammingDis(bitset<8> a, bitset<8> b){
    	bitset<8> x = a xor b;
    	return x.count();
    }
    
    bool check(bitset<8> bit){//推断是否与前面的数距离小于D
    	for(int i = 0; i < result.size(); i++){
    		if(hammingDis(bit, result[i]) < D)
    			return false;
    	}
    	return true;
    }
    
    void DFS(int deep, int count){//deep为搜索的数字,count为确认合法数字的个数,从小往大搜
    	if(deep > MaxDeep)
    		return;
    	if(count > N)
    		return;
    	//
    	bitset<8> tmp(deep + 1);
    	//int dist = hammingDis(last, tmp);
    	if(/*dist >= D*/check(tmp) == true){
    		result.push_back(tmp);
    		last = tmp;
    		DFS(deep + 1, count + 1);
    	}
    	else{
    		DFS(deep + 1, count);
    	}
    	return;
    }
    //==================
    
    int main(){
    	freopen("hamming.in","r",stdin);
    	freopen("hamming.out","w",stdout);
    	cin>>N>>B>>D;
    	MaxDeep = (int)pow(2.0, (double)B) - 1;
    	DFS(-1, 0);
    	for(int i = 0; i < N; i++){
    		cout<<result[i].to_ulong();
    		if(i != N - 1){
    			if(i % 10 == 9)
    				cout<<endl;
    			else
    				cout<<" ";
    		}
    	}
    	cout<<endl;
    	return 0;
    }
    


  • 相关阅读:
    创建文本编辑输入框1:
    表likp新增第一次过账输入日期字段,vl02n/vl01n/vl03n/vl06o的增强
    如何获得控件的属性
    使用OVS
    【Vue】安装(NPM 方法)
    【Webpack】学习随笔
    【node】安装
    【CSS-flex】圣杯布局(Holy Grail Layout)、输入框的布局、悬挂式布局、固定的底栏
    【CSS】关于flex
    解决MySQL新建用户后无法登录问题
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/7215841.html
Copyright © 2011-2022 走看看