【小米】懂二进制

算法与数据结构——小米笔试题 算法题 10:买电影票(小米笔试题) 题目:电影院座位分布是这样,第一排座位号1-5共5个座位,中间是过道,然后6-12共7个座位,第2排13号座位近邻12号座位后面,即首尾相连状,一共30排。共计360个座位。 现在有3个大人和2个小孩一起去看电影,买票有个要求: 1). 5个座位号必须相连(像11 12 13 14 15这样跨排也算); 2). 过道的座位(像1 5 6 12 13等) 阅读详情

题目描述

世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么?

示例1

输入

复制

1999 2299

输出

复制

7
class Solution {
public:
    /**
     * 获得两个整形二进制表达位数不同的数量
     * 
     * @param m 整数m
     * @param n 整数n
     * @return 整型
     */
    int countBitDiff(int m, int n) {
        int sum = m^n;
        int ans=0;
        while(sum)
        {
            ans++;
            sum = sum&(sum-1);
        }
        return ans;
    }
};

 

Ubuntu 24.04中文输入法终极指南:从安装到疑难排解 本文是Ubuntu 24.04中文输入法的完整指南,详细介绍了如何通过图形界面或命令行安装和配置Intelligent Pinyin输入法。内容涵盖IBus框架的运作原理、输入法快捷键调校、模糊音设置,并重点解决了Qt应用无法输入中文的疑难问题,最后提供了Fcitx5备选方案及常见故障的排解方法。 阅读详情

相关推荐

lammps建模(电解液)opls-aa力场的基本流程

lammps建模(电解液)opls-aa力场的基本流程

syj0922的博客 2134

懂二进制

世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 输入例子: 1999 2299输出例子: 7class Solution { public: /** * 获得两个整形二进制表达位数不同的数量 * * @param m 整数m * @param n 整数n * @

Sunburst的专栏 1327

基于大模型的癫痫手术预测与决策系统技术方案文档

基于大模型的癫痫手术预测与决策系统技术方案文档

嵌入式毕设/课设资料清单(速查手册·文档模板·题库,持续更新)→ 见最新文章 977

Count bit

#include <stdio.h> int count_bit1(int num) { int count = 0; while (num > 0) { num &= (num - 1); count++; } return count; } int count_bit2(unsigned int num) { uns...

yangjingxu的专栏 425

经典密码体制(上)

头歌

shannidawang的博客 3086

从零到一:Mx_yolo本地训练与K210部署实战指南

本文详细介绍了从零开始进行Mx_yolo本地模型训练到K210部署的全流程实战指南。涵盖环境配置、数据准备、模型训练与调优、模型转换及K210部署等关键步骤,并提供了常见问题解决方案和性能优化技巧,帮助开发者高效完成AI模型在嵌入式设备的落地应用。

weixin_29081163的博客 252

世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么?

世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 示例1 输入 1999 2299 输出 7 这里我用两种方式(java): 第一种: 把两个整数直接转化为二进制,再对两个二进制进行比较,看有多少位不一样。不过要注意的是,因为转化后的二进制是字符串形式,所以在对

xiaoming1430026911的博客 934

我的AI学习 ai维护工具之langfuse

as_type: Optional[Literal[‘generation’]] = None, # 将记录定义为 Observation (LLM 调用)transform_to_string: Optional[Callable[[Iterable], str]] = None # 将输出转为 string。要用LangFuse的云服务,首先要在LangFuse官网上注册,注册完后将页面拉倒最后,点免费的SignUp,API文档:https://api.reference.langfuse.com/

liubaobin的博客 4096

并行bit count算法

计算一个整型数字中有多少个bit被置1,一般会想到按位循环遍历的方法。 这里有一个并行计算的方法如下: 先上代码 v = v - ((v >> 1) & 0x55555555); // reuse input as temporary v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp c = ((v + (v >> 4) & 0xF0

蓝羽飞鸟的博客 592

AI 技术新手入门与实战指南

仅仅能对话还不够,实际应用中,我们往往需要让 AI 处理特定的业务数据。比如,从日志文件中提取错误码,或者将非结构化的用户反馈整理成 JSON 格式。这时候,自定义输入和严格的结果验证就显得尤为重要。假设我们需要让 AI 分析一段服务器日志,并只返回错误的级别和简述。请分析以下日志片段,提取所有 ERROR 级别的信息。要求输出格式为 JSON 列表,包含 'timestamp' 和 'message' 两个字段。不要输出任何多余的解释文字。日志内容: {

2600_94936330的博客 2681

【光斑定位】空间激光通信、光斑定位、CCD、光斑定位——13000字

0.完整源码获得方式 订阅MATLAB/FPGA教程,免费获得教程案例以及任意2份完整源码 ----------------------------------------------------------------- 空间激光通信是指以光波作为载波进行数据传输的一种通信方式。目前,空间激光通信己成为人们关注的焦点。在空间激光通信系统中,光斑定位是是一项关键技术。 本论文首先对国内外空间激光通信系统的研究现状进行了阐述,论述了空间激光通信的理论只是,并对CCD成像原理,...

FPGA/MATLAB学习教程/源码/项目合作开发 1292

统计单字节、多字节bit位长度

#include //统计一个字节bit为1的个数 unsigned char CountBit(unsigned char value) { unsigned char i=0; unsigned char count=0; while(i<8) { if(value & 0x01) { count++; } value>>=1; i++; } retur

何文斌的专栏 1269

解决Windows 11文件右键菜单卡死问题的方法

当你右键点击一个文件或者文件夹时,系统会加载与该文件类型相关的上下文菜单项,如果其中某个菜单项的代码执行时间过长或者出现错误,就会导致整个右键菜单卡死。综上所述,当你在Windows 11中遇到右键菜单卡死的问题时,你可以尝试禁用上下文菜单项、重置文件关联、排除第三方软件干扰、修复系统文件以及优化代码等方法来解决问题。如果你是一个开发者,并且你自己编写了一个上下文菜单项,那么问题可能出在你的代码中。例如,如果你遇到了图片文件的右键菜单卡死问题,你可以找到".jpg"或".png"等相关的子项。

HnrzLinux的博客 7538

小米 懂二进制

题目描述世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 输入例子: 1999 2299输出例子: 7class Solution { public: /** * 获得两个整形二进制表达位数不同的数量 * * @param m 整数m * @param n 整数n

bleuesprit的专栏 454

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

[小米]懂二进制

时间限制:1秒 空间限制:32768K 热度指数:35899 算法知识视频讲解 题目描述 世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 输入例子: 1999 2299 输出例子: 7思路:在二进制中,统计两个数的相应位不同可以利用异或,运算结果相同为0,不同为1,所以异或结果中1的个数就是不同的位...

weixin_30273175的博客 134

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

小米笔试-懂二进制

题目:世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 输入:1999 2299 输出:7思路判断有多少位不同,我们可以使用异或,把两个数异或之后得到的数,不相同的位就是1。接下来我们只需要统计异或之后的数字有多少位具体代码实现:public int countBitDiff(int m, int n) { i

lizhao007 958

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

小米笔试题 懂二进制

题目描述世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 输入例子: 1999 2299输出例子: 7/** * Created by ustc-lezg on 16/4/8. */ public class Solution { public int countBitDiff(int m, int n) {

不可不戒 788

2016小米-懂二进制-Java

/** * 题目描述 世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? * 示例1 输入 * 1999 2299 * 输出 * 7 * * @author 崔洪振367 * @version 创建时间:2017年6月30日 下午10:34:53 * 解题思路:将两个数逐位相与,如果不等,则计数器加1.

崔洪振367 469

小米笔试题-懂二进制

题目描述: 世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么?  解题思路: 采用移位,可先右移31位,获得最高位的值,判断是否相同,然后再将原值右移1位,一直循环。即可判断 代码: public class Solution { /** * 获得两个整形二进制表达位数不同的数量

一骑红尘妃子笑 599

小米笔试 懂二进制?

int countBitDiff(int m, int n) { /* 解法一 int dif=m^n;//先将二者做异或运算,得到结果; int cnt=0; while(dif!=0){ dif=dif&(dif-1); ++cnt; }

5念since 325

小米-懂二进制 华为-最高分是多少

小米-懂二进制 华为-最高分是多少

demonwang1025的博客 631

懂二进制(16年小米校招)

世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 输入例子: 1999 2299 7 分析:先将2个十进制数异或,然后计算出异或后1的个数,还是经典问题“二进制数中1的个数”,这里只给一种解法,其他的见《编程之美》。#include <iostream> using namespace std; int main(void

奔跑,前进 457

小米技术类测试编程题:懂二进制数

题目描述 世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么?  输入例子: 1999 2299 输出例子: 7 解题思路:见java实现注释 java实现: public class Solution { /** * 获得两个整形二进制表达位数不同的数量 *

221

懂二进制 小米2016年校招 Java实现

世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 输入例子: 1999 2299 输出例子: 7 思路: (1)首先对两个数进行异或操作,就可以得到位数不同的序列值 (2)统计序列值中1的个数 代码实现: public int countBitDiff(int m, int n) { //异或

guo_520_jing的博客 500

2015小米暑期实习笔试题_懂二进制(位运算)

总共3道题,最后一道还没AC出来。。。 世界上有10种人,一种懂二进制,一种不懂。 那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么?  输入例子: 1999 2299 输出例子: 7 此题解法类似于《编程之美》上面看到的某题 代码: #include using namespace std; i

my_adu的专栏 1646
上一篇: 1+2+····+n
下一篇: 【去哪儿】首个重复字符
云水谣CS
博客等级 码龄9年 8粉丝 268原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值