看了大牛的解法  第一次知道可以产生随机数解题   在计算hamming距离时用了位运算  很简便

/*************************************************************************
> Author: xlc2845 > Mail: xlc2845@gmail.com
> Created Time: 2013年10月29日 星期二 15时35分21秒
************************************************************************/ #include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <ctime>
#include <algorithm> using namespace std;
int num[100001];
int hamdist(int x, int y)
{
int sum = 0, w = x ^ y;
while(w)
{
sum++;
w &= w - 1;
}
return sum;
}
int main()
{
int t;
// srand(time(NULL));
// for(int i = 0; i < 100; i++)
// {
// int x = rand()%100;
// int y = rand()%100;
// printf("%d %d\n",x,y);
// }
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%X", &num[i]);
int ans = 30;
for(int i = 0; i < 100000; i++)
{
int x = rand()%n, y = rand()%n;
while(y == x)
y = rand()%n;
ans = min(ans, hamdist(num[x], num[y]));
}
printf("%d\n",ans);
}
return 0;
}

最新文章

  1. pitch yaw roll是什么
  2. JS 模块化和打包方案收集
  3. CMakeLists for tesseract
  4. cat命令在文件中插入内容
  5. Visual Assist 生成注释功能
  6. linux下svn的常用代码【转】
  7. 函数 buf_chunk_init
  8. 重置mysql密码
  9. oracle数据库敏感操作前创建还原点
  10. 解决SQL Server Management Studio Express不支持更新全文目录的方法
  11. BZOJ 1367([Baltic2004]sequence-左偏树+中位数贪心)
  12. mmap学习
  13. Word常用实用知识1
  14. 用UltraISO制作CentOS U盘安装盘
  15. activemq的案例
  16. Java编写高质量代码改善程序的151个建议
  17. css初始化标签属性--源码
  18. [转] xgboost
  19. Javascript和Jquery语法对比总结
  20. Series 入门(创建和增删改查)

热门文章

  1. HDOJ2014青年歌手大奖赛_评委会打分
  2. 利用ExpandableListView和gridview 显示可展开折叠菜单导航
  3. Intent的属性介绍
  4. ubuntu(16.04.01)学习-day1
  5. 使用Emmet(前身Zen Coding)加速Web前端开发
  6. JQuery验证工具
  7. 引用类型之Array类型
  8. 关于remote访问中的flex端配置问题
  9. 如何保证写出来的程序没BUG
  10. 在Linux环境下给php添加mbstring扩展