当前位置: 首页 > news >正文

华为OD机考 - 水仙花数 Ⅰ(2025B卷 100分)

在这里插入图片描述

import java.util.*;
public static Integer get(int count,int c){if(count<3||count>7){return -1;}//存储每位数的最高位……最低位int[] arr =new int[count];List<Integer> res = new ArrayList<>();for(int i=(int) Math.pow(10,count-1);i<(int) Math.pow(10,count);i++){getArr( i,arr);int sum = 0;for(int j = 0;j<arr.length;j++){sum+= Math.pow(arr[j],arr.length);}if(sum == i){res.add(i);}}//System.out.println(res);if(res.size()<c){return res.get(res.size()-1)*c;}return res.get(c);
}public static int[] getArr(int i,int[] arr){int count = 0,j=arr.length;while(count<arr.length){arr[count] = i/ ((int) Math.pow(10,j-1));i = i- arr[count]* ((int) Math.pow(10,j-1));j--;count++;}return arr;
}public static void main(String[] args) {Scanner in = new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseint count = in.nextInt();int c = in.nextInt();System.out.println(get(count, c));}
}
http://www.dtcms.com/a/238102.html

相关文章:

  • 数学建模期末速成 主成分分析的基本步骤
  • Z-FOLD: A Frustratingly Easy Post-Training Quantization Scheme for LLMs
  • 实战:如何用SCINet增强YOLOv8在低照度下的目标检测性能(附完整代码)
  • Linux安全加固:从攻防视角构建系统免疫
  • 打造优质技术文档指南
  • 基于RT-DETR算法的夜间交通车辆与行人目标检测
  • 附加模块--Qt OpenGL模块功能及架构
  • 68常用控件_QGroupBox的使用
  • 【Linux】HAProxy:结合 WG 实现内网 TCP 反代
  • 大数据CSV导入MySQL
  • 微软PowerBI考试 PL300-使用 Power BI 准备数据以供分析【提供练习数据】
  • JDK8新特性之Steam流
  • 通过css实现正方体效果
  • 如何写一篇基于Spring Boot + Vue + 微信小程序的软件的接口文档
  • WEB3全栈开发——面试专业技能点P3JavaScript / TypeScript
  • Secs/Gem第十一讲(基于secs4net项目的ChatGpt介绍)
  • 论文略读:Position: AI Evaluation Should Learn from How We Test Humans
  • SpringCloud学习笔记-4
  • Linux驱动学习day3
  • 动手学深度学习pytorch(第一版)学习笔记汇总
  • 6.8 note
  • el-input,金额千分符自动转换
  • window下配置ssh免密登录服务器
  • RushDB开源程序 是现代应用程序和 AI 的即时数据库。建立在 Neo4j 之上
  • 【网站建设】不同类型网站如何选择服务器?建站项目实战总结
  • 【MySQL系列】MySQL 执行 SQL 文件
  • GeoBoundaries下载行政区划边界数据(提供中国资源shapefile)
  • Linux:守护进程(进程组、会话和守护进程)
  • Ubuntu系统多网卡多相机IP设置方法
  • Prompt工程学习之思维树(TOT)