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

蓝桥杯刷题记录之数字王国之军训排队

记录

卡了半天,check函数中的temp % ele ==0写成了ele % temp == 0就挺无语的

思路

这个晚上在补

代码

import java.util.*;
public class Main{static List<List<Integer>> que = new ArrayList<>();static int MIN = Integer.MAX_VALUE;static int[] people;public static void dfs(int index){if(index==people.length){MIN = Math.min(MIN,que.size());return;}if(index>=MIN)return;int temp = people[index];for(int i=0;i<que.size();i++){//能加入队伍List<Integer> list = que.get(i);if(check(list,temp)){list.add(temp);dfs(index+1);list.remove(list.size()-1);}}// 自立门户List<Integer> item =new LinkedList<>();item.add(temp);que.add(item);dfs(index+1);que.remove(que.size()-1);}private static boolean check(List<Integer> list, int temp) {for(Integer ele: list){if(temp % ele ==0)return false;}return true;}public static void main(String[] args) {Scanner s = new Scanner(System.in);int n = s.nextInt();people = new int[n];for(int i=0;i<n;i++){people[i] = s.nextInt();}Arrays.sort(people);List<Integer> item = new LinkedList<>();item.add(people[0]);que.add(item);dfs(1);System.out.println(MIN);s.close();}
}
http://www.lryc.cn/news/322964.html

相关文章:

  • Go语言学习Day1:什么是Go?
  • C语言内存函数之 memcmp函数
  • 3. C++ 常见的段错误及对策
  • 推荐的Kubernetes 学习资料
  • MySQL之索引与事务
  • Linux的基本使用
  • 亚信安慧AntDB全景观察:数据库领域的创新者
  • Linux 系统是如何收发⽹络包的
  • 飞跃前端瓶颈:技术进阶指南精华篇
  • Jenkins安装 Linux 更换镜像 安装插件
  • (一)基于IDEA的JAVA基础1
  • FPGA开源项目分享——基于FPGA加速的热扩散模拟器
  • 【ARM 嵌入式 C 入门及渐进 12 --寄存器位清0和置位函数实现】
  • Java实现10万,并发去重,优雅地处理重复请求!
  • 《深入解析 C#》—— C# 3 部分
  • Redis 的5种数据类型的基本命令
  • 【Liunx-后端开发软件安装】Liunx安装nginx
  • 力扣Lc20--- 202.快乐数(java版)-2024年3月20日
  • 机器学习----交叉熵(Cross Entropy)如何做损失函数
  • Linux docker3--数据卷-nginx配置示例
  • 力扣454. 四数相加 II
  • vulnstack1 渗透分析 红日靶场(一)
  • 外包干了6天,技术明显进步。。。
  • 比较好的知识点
  • 抖音开放平台的订单类API接口调用测试指南(内含详细步骤)
  • HiveSQL一本通 - 案例实操
  • Axure RP 8中文---快速原型设计工具,一站式解决方案
  • Available platform plugins are: minimal, offscreen, webgl, windows.
  • 创意无限,风险有度:2024愚人节海外网红营销策略解析
  • 深入理解 Session、Cookie 和 Token:网络安全和身份验证的重要概念