HDU4712 Hamming Distance (随机化)
link:http://acm.hdu.edu.cn/showproblem.php?pid=4712
题意:给1e5个数字,输出这些数中,最小的海明码距离。
思路:距离的范围是0到20。而且每个数的数位都很有限的,然后一言不合开始
随机。随机算法虽然挺惊艳的,不过求随机算法成功概率,臣妾做不到啊!
总之,遇上暴力很难得到优化,但AC掉一片的题,随机算法这样的奇策应当信手
拈来!这是强大洞察之力的体现~
#include <iostream>
#include <algorithm>
using namespace std;
const int NICO = 100000+10;
int T, n, a[NICO];
int main()
{
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i=1;i<=n;i++)
{
scanf("%X", &a[i]);
}
int ans = 22;
for(int i=1;i<=500000;i++)
{
int x = rand()%n+1;
int y = rand()%n+1;
if(x == y) continue;
int v = a[x]^a[y];
ans = min(ans, __builtin_popcountl(v));
}
printf("%d\n", ans);
}
}
HDU4712 Hamming Distance (随机化)的更多相关文章
- hdu4712 Hamming Distance
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) To ...
- HDU 4217 Hamming Distance 随机化水过去
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- [LeetCode] Total Hamming Distance 全部汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [LeetCode] Hamming Distance 汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- Total Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- 461. Hamming Distance and 477. Total Hamming Distance in Python
题目: The Hamming distance between two integers is the number of positions at which the corresponding ...
- LeetCode Total Hamming Distance
原题链接在这里:https://leetcode.com/problems/total-hamming-distance/ 题目: The Hamming distance between two i ...
- LeetCode Hamming Distance
原题链接在这里:https://leetcode.com/problems/hamming-distance/ 题目: The Hamming distance between two integer ...
随机推荐
- c#实现list,dataset,DataTable转换成josn等各种转换方法总和
using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Refle ...
- jqzoom插件
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...
- AutoMapper.RegExtension[.NET Core版本] 介绍
Technorati 标签: AutoMapper.RegExtension,AutoMapper.RegExtension .NET CORE AutoMapper.RegExtension 为一个 ...
- Struts2之Validator
Struts2中提供了数据校验验证数据例如验证邮件.数字等.验证方式有3种:一是通过validate()方法,二是通过Xml,三是使用注解方式. 一.初始化 首先定义一个User类 package c ...
- Kubernetes使用cephfs作为后端存储
这里使用了k8s自身的持久化卷存储机制:PV和PVC.各组件之间的关系参考下图: PV的Access Mode(访问模式) The access modes are: ReadWriteOnce – ...
- 爬虫入门系列(一):快速理解HTTP协议
4月份给自己挖一个爬虫系列的坑,主要涉及HTTP 协议.正则表达式.爬虫框架 Scrapy.消息队列.数据库等内容. 爬虫的基本原理是模拟浏览器进行 HTTP 请求,理解 HTTP 协议是写爬虫的必备 ...
- net.sz.framework 框架 轻松搭建数据服务中心----读写分离数据一致性,滑动缓存
前言 前文讲述了net.sz.framework 框架的基础实现功能,本文主讲 net.sz.framework.db 和 net.sz.framework.szthread; net.sz.fram ...
- java基础之类与对象1
从学习java到现在估计都有一年了,然而在这一年里基本处于三天打鱼五天晒网,感觉自己再不做点改变就是个废人了..T - T. 趁着重新复习java的时间,也顺便用博客来记录学习的过程.好了,废话不说了 ...
- C#---------------继承和多态初步
继承:在程序中,如果一个类A:类B,这种机制就是继承. 子类可以继承父类的所有内容(成员)吗? 解析: 1.私有成员(属性和方法) 2.构造函数 3.final修饰过的方法,子类不能进行重写 3.访问 ...
- NodeJs之http
创建新的服务器 创建一个简单的服务 var http = require("http"); var server = http.createServer(); server.lis ...