杭州电 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 ...
随机推荐
- 修改注册表添加IE信任站点及启用Activex控件
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/In ...
- JSTL解析——004——core标签库03
上面章节主要讲解<c:forEach>标签,下面讲解其它标签 1.<c:forTokens>标签 forTokens标签与forEach标签类似,独有begin.end.ste ...
- 搜索:POJ2251&POJ1426&POJ3087&POJ2488
图的遍历也称为搜索,就是从图中某个顶点出发,沿着一些边遍历图中所有的顶点,且每个顶点仅被访问一次,遍历可采取两种不同的方式:深度优先搜索(DFS)和广度优先搜索(BFS). 1.DFS算法思想` 从顶 ...
- Mojo Mysql utf-8字符集 需要{mysql_enable_utf8 => 1}
get '/api/log_mon/get_log' => sub{ my $c = shift; my $env = $c->param('env'); my $host = $c-&g ...
- NET Core 中的依赖注入
NET Core 中的依赖注入 [共7篇] 一.控制反转(IoC) ASP.NET Core在启动以及后续针对每个请求的处理过程中的各个环节都需要相应的组件提供相应的服务,为了方便对这些组件进行定制, ...
- 高逼格UI-ASD(Android Support Design)
绪 今年的Google IO给我们android开发着带来了三样非常屌非常屌的library: ASD(Android Support Design) APL(Android Percent Layo ...
- counting objects in class
參考文献:pgno=1">http://www.drdobbs.com/cpp/counting-objects-in-c/184403484? pgno=1
- 访何红辉:谈谈Android源码中的设计模式
最近Android 6.0版本的源代码开放下载,刚好分析Android源码的技术书籍<Android源码设计模式解析与实战>上市,我们邀请到它的作者何红辉,来谈谈Android源码中的设计 ...
- iptables 小结
最近工作上一个作业用到了iptables命令,主要进行端口映射,在网上查了好多资料,尽管有很多例子,但还是整了好几天才整明白.在这里将学习到的知识总结一下.以下均属个人见解.(有一些是从网络中总结的, ...
- spring MVC 下载文件(转)
springle MVC中如何下载文件呢? 比struts2 下载文件简单得多 先看例子: @ResponseBody @RequestMapping(value = "/download& ...