[HDOJ3711]Binary Number(枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3711
题意:两个数集合,找二进制下位数不同最少的数,如果一样,找集合数最小的。
暴力枚举
#include <bits/stdc++.h>
using namespace std; const int maxn = ;
int n, m;
int a[maxn], b[maxn]; int ok(int x, int y) {
int xx = x, yy = y; int cnt = ;
if(x > y) swap(x, y);
while(x) {
if((x&)!=(y&)) cnt++;
x >>= ; y >>= ;
}
while(y) {
if(y&) cnt++;
y >>= ;
}
return cnt;
} int main() {
//freopen("in", "r", stdin);
int T;
scanf("%d", &T);
while(T--) {
scanf("%d %d", &n, &m);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
for(int i = ; i <= m; i++) scanf("%d", &b[i]);
for(int i = ; i <= m; i++) {
int ret = , k;
for(int j = ; j <= n; j++) {
int tmp = ok(b[i], a[j]);
if(ret > tmp) {
ret = tmp;
k = j;
}
else if(ret == tmp) {
if(a[k] > a[j]) k = j;
}
}
cout << a[k] << endl;
}
}
return ;
}
[HDOJ3711]Binary Number(枚举)的更多相关文章
- HDU 3711 Binary Number
Binary Number Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- [HDU] 3711 Binary Number [位运算]
Binary Number Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 杭州电 3711 Binary Number
Binary Number Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- BNU 13024 . Fi Binary Number 数位dp/fibonacci数列
B. Fi Binary Number A Fi-binary number is a number that contains only 0 and 1. It does not conta ...
- 【Leetcode_easy】693. Binary Number with Alternating Bits
problem 693. Binary Number with Alternating Bits solution1: class Solution { public: bool hasAlterna ...
- 2019长安大学ACM校赛网络同步赛 J Binary Number(组合数学+贪心)
链接:https://ac.nowcoder.com/acm/contest/897/J 来源:牛客网 Binary Number 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32 ...
- 693. Binary Number with Alternating Bits - LeetCode
Question 693. Binary Number with Alternating Bits Solution 思路:输入一个整数,它的二进制01交替出现,遍历其二进制字符串,下一个与上一个不等 ...
- hdu 3711 Binary Number(暴力 模拟)
Problem Description For non-negative integers x and y, f(x, y) , )=,f(, )=, f(, )=. Now given sets o ...
- [LeetCode] Binary Number with Alternating Bits 有交替位的二进制数
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
随机推荐
- 似是而非的k=sqrt(n)
//题目:输入一个大于3的整数n,判定它是否为素数(prime,又称质数)#include <stdio.h>#include <math.h>int main(){int n ...
- mysql grant用户权限设置
MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. grant sele ...
- 我是如何对网站CSS进行架构的
by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/wordpress/?p=944 一.写在前面的 ...
- JSP01
<%@page pageEncoding="UTF-8" //page:设置此文件的编码 contentType="text/html;charset=utf ...
- 【python cookbook】【字符串与文本】12.文本过滤和清理
问题:例如清除在web页面表单中填入了pýtĥöñis这样的文本 解决方法:str.translate()方法 s = 'p\xfdt\u0125\xf6\xf1\x0cis\tawesome\r\n ...
- React笔记_(1)_react概述
React概述 React是一种很好的前端技术. 它将应用打散成独立的小模块,然后进行组装,完成开发. react远比angularjs难学的多. react依赖的如webpack等各种工具得先学 ...
- top.location.href和localtion.href有什么不同
top.location.href=”url” 在顶层页面打开url(跳出框架) self.location.href=”url” 仅在本页面打开url地址 pare ...
- 转:Spring AOP术语
1.连接点(Joinpoint) 程序执行的某个特定位置:如类开始初始化前.类初始化后.类某个方法调用前.调用后.方法抛出异常后.这些代码中的特定点,称为“连接点”.Spring仅支持方法 ...
- [转]linux主机644、755、777权限详解
转自:http://my.oschina.net/qihh/blog/73135 从左至右,第一位数字代表文件所有者的权限,第二位数字代表同组用户的权限,第三位数字代表其他用户的权限. 从左至右,第一 ...
- Install Hive
一.Hive将元数据存储在RDBMS中,有三种模式可以连接到数据: 1.single User Mode:此模式连接到一个In-memory的数据库Derby,一般用于Unit Test. 2.Mul ...