HDU4712-----Hamming Distance------超级大水题
本文出自:http://blog.csdn.net/dr5459
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4712
题目意思:
海明距离:任意两个树异或后二进制含1的个数
要你求出最小的海明距离
解题思路:
因为数的格式是固定的,所以可以预处理16进制中任意两个数的异或1的个数
这样在求的时候,可以在O(5)内求出
至于怎么去求所有的,看的群里的思路,随机10W次,而且要保证随机的两个数不同,我随机了6W次
然后就A了,就A了,真的被吓到了,下面上代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std; int cmp[16][16]; char data[1000005][6]; int fun(int q,int w)
{
int a,b;
int ret = 0;
for(int i=0;i<5;i++)
{
char x = data[q][i];
char y = data[w][i];
if(x>='0' && x<='9')
a=x-'0';
else
a=x-'A'+10; if(y>='0' && y<='9')
b=y-'0';
else
b=y-'A'+10; ret += cmp[a][b];
}
return ret;
} int main()
{
for(int i=0;i<=15;i++)
{
for(int j=0;j<=15;j++)
{
int ans=0;
int tmp = i^j;
for(int k=0;k<4;k++)
if((1<<k) & tmp)
ans++;
//cout<<i<<" "<<j<<" "<<ans<<endl;
cmp[i][j] = ans;
}
} int n;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%s",data[i]); int ans = 0x3f3f3f3f;
srand( (unsigned)time( NULL ) );
for(int i=1;i<=60000;i++)
{
int a = rand()%n+1;
int b = rand()%n+1;
if(a==b)
b = b%n+1;
int tmp = fun(a,b);
if(tmp < ans)
ans = tmp;
} cout<<ans<<endl;
} return 0;
}
HDU4712-----Hamming Distance------超级大水题的更多相关文章
- hdu4712 Hamming Distance
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) To ...
- HDU4712 Hamming Distance (随机化)
link:http://acm.hdu.edu.cn/showproblem.php?pid=4712 题意:给1e5个数字,输出这些数中,最小的海明码距离. 思路:距离的范围是0到20.而且每个数的 ...
- hdu 1228 A+B 字符串处理 超级大水题
中文意思不解释. 很水,我本来想用switch处理字符串,然后编译不通过...原来switch只能处理整数型的啊,我都忘了. 然后就有了很挫的一大串if代码了... 代码: #include < ...
- hdu 1229 超级大水题
Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status Desc ...
- hdu 4548 美素数 超级大水题
美素数 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submis ...
- Lweb and String 超级大水题
Lweb and String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- Total 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 ...
随机推荐
- search_word
一个小程序,用asc码输出自己的名字.要求是,a~z两路输入,输出了一个完整的拼音之后还需要输出一个空格.—— 信息硬件过滤的雏形. module search_word ( clock , rese ...
- C++将文件内容一次性读入内存
结合字符串流,将文件中的内容一次性读入内存,代码如下: #include <string> using std::ostringstream; using std::ifstream; u ...
- 动画api说明
1.Animation的API参考文档:http://blog.csdn.net/harvic880925/article/details/40117115 2.动画插值器的参考: http://bl ...
- Mac删除废纸篓中的单一文件和文件夹
http://www.macappbox.com/tips/159/ 通过Automator创建教程: 1.打开Automator并选择新建 2.选择服务类型 3.搜索Run Shell Script ...
- 15-UIKit(view布局、Autoresizing)
目录: 1. 纯代码布局 2. 在View中进行代码布局 3. Autoresizing 回到顶部 1. 纯代码布局 纯代码布局分VC下和V下 [MX1-layout-code] 在VC下覆盖view ...
- 13-UIKit(tableviewcell贴图、手势GestureRecognizer、transform变形)
目录: 一.tableviewcell贴图 二.手势GestureRecognizer 5.1 Tap(按一下) 5.2 Swipe(轻扫一下) 5.3 pinch(捏/扩) 5.4 longPres ...
- MvvmLight Messenger(信使)
MvvmLight信使需要三个部分: 1.自定义信件类,普通的Model,供在发布者和订阅者之间传递信息用. 2.发布,通常是在某一事件函数中进行发布,Messenger.Default.Send 3 ...
- pytesser图片文本识别
python图片文本识别使用的工具是PIL和pytesser.因为他们使用到很多的python库文件,为了避免一个个工具的安装,建议使用pythonxy,这个工具的介绍可参考baidu. pytess ...
- Android屏幕大小适配问题解决
转载: 一.一些基本概念 1.长度(真实长度):英寸.inch 2.分辨率:density 每英寸像素数 dpi(密度) 3.像素:px 4.dip的公式:px /dip=dpi/160 所以 d ...
- FileStream -- 复制文件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...