当前位置: 首页 > 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));}
}

相关文章:

  • 数学建模期末速成 主成分分析的基本步骤
  • 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(第一版)学习笔记汇总
  • 网站建设教程所需文字/境外电商有哪些平台
  • 公司网站建设的费用/广州seo效果
  • 做企业网站步骤/互联网推广是什么工作内容
  • 广西住房与建设厅网站首页/重庆电子商务seo
  • 微信手机官方网站/百度识图在线网页版
  • 乌鲁木齐做网站哪家好/百度搜索指数是怎么计算的