hdu 4712
2024-10-11 16:00:16
看了大牛的解法 第一次知道可以产生随机数解题 在计算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;
}
最新文章
- pitch yaw roll是什么
- JS 模块化和打包方案收集
- CMakeLists for tesseract
- cat命令在文件中插入内容
- Visual Assist 生成注释功能
- linux下svn的常用代码【转】
- 函数 buf_chunk_init
- 重置mysql密码
- oracle数据库敏感操作前创建还原点
- 解决SQL Server Management Studio Express不支持更新全文目录的方法
- BZOJ 1367([Baltic2004]sequence-左偏树+中位数贪心)
- mmap学习
- Word常用实用知识1
- 用UltraISO制作CentOS U盘安装盘
- activemq的案例
- Java编写高质量代码改善程序的151个建议
- css初始化标签属性--源码
- [转] xgboost
- Javascript和Jquery语法对比总结
- Series 入门(创建和增删改查)