[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 ...
随机推荐
- SQL分组取每组前一(或几)条记录(排名)
mysql分组取每组前几条记录(排名) 附group by与order by的研究 http://www.jb51.net/article/31590.htm --按某一字段分组取最大(小)值所在行的 ...
- opencv载入,显示及保存图像
1.声明一个表示图像的变量,在OpenCV2中,这个变量是cv::Mat类型,该类是用于保存图像以及其他矩阵数据的数据结构.默认情况下它们的尺寸为0. cv::Mat image; // ...
- android 学习随笔十(网络:get、post提交数据)
1.get public class Tools { public static String getTextFromStream(InputStream is){ byte[] b = new by ...
- android 学习随笔三(测试与单元测试框架)
测试 1.按岗位: 黑盒测试:测试业务逻辑 白盒测试:测试逻辑方法 2.按测试粒度 方法测试 function 单元测试 unit 集成测试 integration 系统测试 system 3.按暴力 ...
- 使用git和github托管个人项目
1. 安装 cygwin 和 cygwin 下的 git , 测试 git 命令可用; 参考: https://cygwin.com/install.html 2. 注册 github 账号: ...
- STM32外部中断.
void EXTIX_Init(void){ EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructu ...
- arduino 蓝牙控制RGB LED灯
/* 日期:2016.9.2 功能:arduino 蓝牙控制RGB LED灯 元件: 跳线公公头 * 8 rgbled, 220欧电阻 蓝牙模块 接线: 蓝牙模块VCC,GND分别接5V,GND;TX ...
- Android消息处理机制(Handler 与Message)---01
一.handler的使用场景为么会有handler?(部分内容图片摘自http://www.runoob.com/w3cnote/android-tutorial-handler-message.ht ...
- Redis 安装与简单示例 01_转
一.Redis的安装 Redis下载地址如下:https://github.com/dmajkic/redis/downloads 解压后根据自己机器的实际情况选择32位或者64位.下载解压后图片如下 ...
- oracle ORA-12519,TNS:no appropriate service handler found的
select count(*) from v$process --当前的连接数 select value from v$parameter where name = 'processes' --数据库 ...