杭州电 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 ...
随机推荐
- wiki 3143 二叉树的前序、中序及后序遍历
先序遍历:訪问根.遍历左子树.遍历右子树,简称:DLR. 中序遍历:遍历左子树,訪问根,遍历右子树,简称:LDR. 后序遍历:遍历左子树,遍历右子树.訪问根.简称:LRD. 数组搞的: #pragma ...
- linux 配置 mail server
一.配置yum安装工具 ① 进入yum目录 [root@bj ~]# cd /etc/yum.repos.d ② 配置yum.repo [root@bj yum.repos.d]# cprhel- ...
- Abot 爬虫
Abot 爬虫分析-整体结构 1. 引言 在Github 上搜索下Web Crawler 有上千个开源的项目,但是C#的仅仅只有168 个,相比于Java 或者Python 确实少的可怜.如果按照St ...
- C++ 多源码文件简单组织
C++ 多源码文件简单组织 基本上和C的是一样的,只不过C++的方法要在类中声明.看一个简单实例.ainimal.h 类里面对外公开的信息. 点击(此处)折叠或打开 #ifndef _ANIMAL_ ...
- hdu 4284 Travel(floyd + TSP)
虽然题中有n<=100个点,但实际上你必须走过的点只有H<=15个.而且经过任意点但不消耗C[i]跟D[i]可以为无限次,所以可以floyd预处理出H个点的最短路,之后剩下的...就成了裸 ...
- C# split字符串 依据1个或多个空格
实例场景.对于字符串:"AAAA AAA BBBB BBB BBB CCCCCCCC". 1. 分隔为 "AAAA AAA" . & ...
- mysql 高可用方案MHA介绍
概述 MHA是一位日本MySQL大牛用Perl写的一套MySQL故障切换方案,来保证数据库系统的高可用.在宕机的时间内(通常10—30秒内),完成故障切换,部署MHA,可避免主从一致性问题,节约购买新 ...
- Iterator 和 Iterable 差别和联系
用Iterator模式实现遍历集合 Iterator模式是用于遍历集合类的标准訪问方法.它能够把訪问逻辑从不同类型的集合类中抽象出来,从而避免向client暴露集合的内部结构. 比如,假设没有使用I ...
- matlab图形矢量化解决方案
大致思路:matlab中生成矢量格式文件-导入Visio中-编辑-导出合适格式-在其他软件中使用 准备工具 Matlab 2014b或更高版本 Visio 2007或更高版本 我查看过,Matlab能 ...
- 使用xml和java代码混合控制UI界面
main.xml.................... <?xml version="1.0" encoding="utf-8"?> <Li ...