HDOJ 1390 Binary Numbers(进制问题)

简介: HDOJ 1390 Binary Numbers(进制问题)

Problem Description

Given a positive integer n, find the positions of all 1’s in its binary representation. The position of the least significant bit is 0.


Example


The positions of 1’s in the binary representation of 13 are 0, 2, 3.


Task


Write a program which for each data set:


reads a positive integer n,


computes the positions of 1’s in the binary representation of n,


writes the result.


Input

The first line of the input contains exactly one positive integer d equal to the number of data sets, 1 <= d <= 10. The data sets follow.


Each data set consists of exactly one line containing exactly one integer n, 1 <= n <= 10^6.


Output

The output should consists of exactly d lines, one line for each data set.


Line i, 1 <= i <= d, should contain increasing sequence of integers separated by single spaces - the positions of 1’s in the binary representation of the i-th input number.


Sample Input

1

13


Sample Output

0 2 3


思路:

就是输入一个数n,n二进制假如为m。

就是输出二进制m这个数的1所在的位数。从小到大输出。

例如:输入13.

13的二进制数是1101;

所以输出为:0 2 3

注意,最后一个数字后面没有接空格。

import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int n =sc.nextInt();
            String nstr = Integer.toString(n, 2);
            //System.out.println(nstr);
            boolean isOne=true;
            for(int i=nstr.length()-1;i>=0;i--){
                if(nstr.charAt(i)=='1'){
                    if(isOne){
                        System.out.print(nstr.length()-1-i);
                        isOne=false;
                    }else{
                        System.out.print(" "+(nstr.length()-1-i));
                    }
                }
            }
            System.out.println();
        }
    }
}
目录
相关文章
|
8天前
|
数据采集 人工智能 安全
|
4天前
|
机器学习/深度学习 人工智能 前端开发
构建AI智能体:七十、小树成林,聚沙成塔:随机森林与大模型的协同进化
随机森林是一种基于决策树的集成学习算法,通过构建多棵决策树并结合它们的预测结果来提高准确性和稳定性。其核心思想包括两个随机性:Bootstrap采样(每棵树使用不同的训练子集)和特征随机选择(每棵树分裂时只考虑部分特征)。这种方法能有效处理大规模高维数据,避免过拟合,并评估特征重要性。随机森林的超参数如树的数量、最大深度等可通过网格搜索优化。该算法兼具强大预测能力和工程化优势,是机器学习中的常用基础模型。
298 164
|
3天前
|
机器学习/深度学习 自然语言处理 机器人
阿里云百炼大模型赋能|打造企业级电话智能体与智能呼叫中心完整方案
畅信达基于阿里云百炼大模型推出MVB2000V5智能呼叫中心方案,融合LLM与MRCP+WebSocket技术,实现语音识别率超95%、低延迟交互。通过电话智能体与座席助手协同,自动化处理80%咨询,降本增效显著,适配金融、电商、医疗等多行业场景。
307 155
|
11天前
|
SQL 自然语言处理 调度
Agent Skills 的一次工程实践
**本文采用 Agent Skills 实现整体智能体**,开发框架采用 AgentScope,模型使用 **qwen3-max**。Agent Skills 是 Anthropic 新推出的一种有别于mcp server的一种开发方式,用于为 AI **引入可共享的专业技能**。经验封装到**可发现、可复用的能力单元**中,每个技能以文件夹形式存在,包含特定任务的指导性说明(SKILL.md 文件)、脚本代码和资源等 。大模型可以根据需要动态加载这些技能,从而扩展自身的功能。目前不少国内外的一些框架也开始支持此种的开发方式,详细介绍如下。
846 6
|
5天前
|
机器学习/深度学习 人工智能 前端开发
构建AI智能体:六十九、Bootstrap采样在大模型评估中的应用:从置信区间到模型稳定性
Bootstrap采样是一种通过有放回重抽样来评估模型性能的统计方法。它通过从原始数据集中随机抽取样本形成多个Bootstrap数据集,计算统计量(如均值、标准差)的分布,适用于小样本和非参数场景。该方法能估计标准误、构建置信区间,并量化模型不确定性,但对计算资源要求较高。Bootstrap特别适合评估大模型的泛化能力和稳定性,在集成学习、假设检验等领域也有广泛应用。与传统方法相比,Bootstrap不依赖分布假设,在非正态数据中表现更稳健。
239 113