http://acm.hdu.edu.cn/showproblem.php?pid=4712

题意:计算任意两个十六进制的数异或后1的最少个数。

思路:用随机数随机产生两个数作为下标,记录这两个数异或后1的个数,输出1的个数最少是多少。

 #include <stdio.h>
#include <algorithm>
#include <time.h>
#include <math.h> using namespace std;
const int N=;
const int INF=<<;
int f[N];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,ans = INF;
scanf("%d",&n);
for (int i = ; i < n; i ++)
scanf("%x",&f[i]);
srand((unsigned)time(NULL));
for (int i = ; i < N*; i ++)
{
int a = rand()%n;
int b = rand()%n;
if (a==b)
continue ;
int t = f[a]^f[b];
int temp = __builtin_popcount(t);
ans = min(ans,temp);
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. Thinkphp批量添加数据
  2. 更加简洁易用——wangEditor富文本编辑器新版本发布
  3. (转)CSS 为不同大小的浏览器视窗使用不同的样式表
  4. JSP SQL注入--破法
  5. Mysql 储存过程以及 python callproc调用
  6. Keywords Search (ac 自己主动机)
  7. UpdataData
  8. C利用宏语言(#,##,do…while(0)盛大)
  9. 从头编写 asp.net core 2.0 web api 基础框架 (5) EF CRUD
  10. SQL Server 数据类型转换函数
  11. Docker Mongo数据库开启用户认证
  12. MySql常用命令集Mysql常用命令3
  13. Linux CentOS 6.9 Minimal 编译 OpenJDK 7
  14. Let Encrypt延期(转自虞大胆的叽叽喳喳)
  15. 浅谈sql中的in与not in,exists与not exists的区别以及性能分析
  16. 从Web Service和Remoting Service引出WCF服务
  17. transitionFromView方法的使用
  18. C#中[] 、List、Array、ArrayList等数据结构的差异简述
  19. PHP excel reader , excel时间转成php时间格式
  20. 部署jenkins问题

热门文章

  1. lamlmzhang的新博客开通了,欢迎大家的关注
  2. 郁闷的出纳员 题解(Splay)
  3. 什么是ACID
  4. 网络编程:tcp、udp、socket、struct、socketserver
  5. 安装RHEL7红帽操作系统
  6. Python - 面对对象(基础)
  7. android 数据存储之SQLite
  8. ES6-babel转码
  9. ISNUMERIC()检测是否为数字
  10. 【[Offer收割]编程练习赛 14 B】投掷硬币