首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

HDU 4712 Hamming Distance [预加工+暴力]

2013-09-09 
HDU 4712 Hamming Distance[预处理+暴力]惨不忍睹,不能多说了。直接看代码吧。。。就是暴力了。。。#include cst

HDU 4712 Hamming Distance [预处理+暴力]

惨不忍睹,不能多说了。直接看代码吧。。。

就是暴力了。。。


#include <cstdio>#include <iostream>#include <cstring>#include <vector>#include <algorithm>using namespace std;#define N 100020int a[N<<1], n;vector<int> c[22];int f[1<<21];int main() {#ifndef ONLINE_JUDGE    freopen("in.txt", "r", stdin);#endif    for (int i=0; i<22; i++) c[i].clear();    int cnt, T;    for (int i=0; i<(1<<21); i++) {        cnt = 0;        for (int j=0; j<21; j++) if (i & (1<<j)) cnt++;        c[cnt].push_back(i);    }    scanf("%d", &T);    while (T--) {        scanf("%d", &n);        memset(f, 0, sizeof(f));        bool ok = false;        for (int i=0; i<n; i++) {            scanf("%X", &a[i]);            if (++f[a[i]] >= 2) ok = true;        }        if (ok) { puts("0") ; goto foo;}        for (int i=1; i<21; i++)            for (int j=0; j<n; j++)                for (int k=0; k<c[i].size(); k++) {                    if (f[a[j] ^ c[i][k]]) {                        printf("%d\n", i);                        goto foo;                    }                }foo:        ;    }    return 0;}


热点排行