杭州电 3711 Binary Number
Binary Number
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1287 Accepted Submission(s): 807
b in B, you should find an integer a in A such that f(a, b) is minimized. If there are more than one such integer in set A, choose the smallest one.
A and B, respectively. Then follow (m + n) lines, each of which contains a non-negative integers no larger than 1000000. The first m lines are the integers in set A and the other n lines are the integers in set B.
2
2 5
1
2
1
2
3
4
5
5 2
1000000
9999
1423
3421
0
13245
353
1
2
1
1
1
9999
0
AC代码例如以下:
#include <stdio.h>
int a[105];
int count(int x)
{
int c = 0;
for(;x;x>>=1) if(x&1) c++;
return c;
}
int main()
{
int b, i, j, n, m, k, min, t,cases;
scanf("%d",&cases);
while(cases--)
{
scanf("%d%d",&n,&m);
for(i=0; i<n; i++) scanf("%d",&a[i]);
for(i=0; i<m; i++)
{
scanf("%d",&b);
min = count(b^a[0]);
k = 0;
for(j=1; j<n; j++)
{
t = count(b^a[j]);
if(t<min||t==min&&a[j]<a[k])
{ min = t;k = j;}
}
printf("%d\n",a[k]);
}
}
return 0;
}
杭州电 3711 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 ...
- hdu 3711 Binary Number(暴力 模拟)
Problem Description For non-negative integers x and y, f(x, y) , )=,f(, )=, f(, )=. Now given sets o ...
- hdu 1290 竭诚为杭州电礼物50周年
专门为杭州电50周年礼事 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- 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交替出现,遍历其二进制字符串,下一个与上一个不等 ...
- [LeetCode] Binary Number with Alternating Bits 有交替位的二进制数
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
随机推荐
- 【Demo 0010】事件响应链
本章学习要点: 1. 熟悉iOS事件分发过程以及事件响应链; 2. 掌握基本事件响应方法(单击,双击): 3. 掌握基本手势处理方法:
- 给你的站点加入 console.js
本文仅先给使用console调试的FE同学,假设你还不知道console是什么.或者还停留在alert阶段,那就不要浪费时间了,say bay bay! 你是否试程序的过程中用过console.log ...
- 在phpmyadmin后台获取webshell方法汇总整理
方法一: CREATE TABLE `mysql`.`xiaoma` (`xiaoma1` TEXT NOT NULL ); INSERT INTO `mysql`.`xiaoma` (`xiaoma ...
- SQL中如何将一个表中的某一列的数据复制到另一个表中的某一列里
表一: SPRD PRD_NO SPC 001 NULL 002 NULL 003 NULL ... ...
- Detours信息泄漏漏洞
v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...
- [Network]Wireless and Mobile
Wireless 1 Introduction 1.1 Elements 1. Wireless Hosts Wireless does not mean mobility. 2. Base Stat ...
- linux下安装QT过程
说QT是linux下主要的图形开发工具一点都不过分,虽然诺基亚公司放弃Meego.遣散了Qt开发团队,但是它的各种商业.企业版本还是的到了很好的保护,linux下的开发工具集里还是经常看到它的身影,毕 ...
- Android 布局之LinearLayout 子控件weight权重的作用详析(转)
关于Android开发中的LinearLayout子控件权重android:layout_weigh参数的作用,网上关于其用法有两种截然相反说法: 说法一:值越大,重要性越高,所占用的空间越大: 说法 ...
- hdu2062(递推)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2062 详细分析:http://mamicode.com/info-detail-95273.html ...
- hdu1158(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1158 分析:dp[i][j]表示第i个月用j个人需要花费的最少费用: 则状态转移方程为:dp[i][j ...