码迷,mamicode.com
首页 > 其他好文 > 详细

USACO hamming 继续暴搜

时间:2014-06-17 22:21:36      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:class   blog   code   com   strong   2014   

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;
}


USACO hamming 继续暴搜,布布扣,bubuko.com

USACO hamming 继续暴搜

标签:class   blog   code   com   strong   2014   

原文地址:http://blog.csdn.net/kevin_samuel/article/details/31384753

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!