当前位置:   article > 正文

华为od机考_机器人仓库搬砖_Java_java 机器人仓库搬砖

java 机器人仓库搬砖

题目

代码

  1. public static int t1(int[] input){
  2. if(input.length > 8){
  3. return -1;
  4. }
  5. int minResult = Integer.MAX_VALUE;
  6. int minNum = Integer.MAX_VALUE;
  7. int maxNum = Integer.MIN_VALUE;
  8. for(int i = 0; i < input.length; i++){
  9. if(input[i] < minNum){
  10. minNum = input[i];
  11. }
  12. if(input[i]> maxNum){
  13. maxNum = input[i];
  14. }
  15. }
  16. for(int n = 1; n <= maxNum; n++){
  17. int count = 0;
  18. for(int i = 0; i < input.length; i++){
  19. if(input[i] % n == 0){
  20. count += (input[i]/n);
  21. } else {
  22. count += (input[i]/n + 1);
  23. }
  24. }
  25. if(count <= 8){
  26. minResult = (minResult > n)? n:minResult;
  27. }
  28. }
  29. return minResult;
  30. }
  31. public static void main(String[] args) {
  32. Scanner in = new Scanner(System.in);
  33. String[] inputValues = in.nextLine().split(" ");
  34. int[] input = new int[inputValues.length];
  35. for(int i = 0; i < inputValues.length; i++){
  36. input[i] = Integer.valueOf(inputValues[i]);
  37. }
  38. System.out.println(t1(input));
  39. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/940055
推荐阅读
相关标签
  

闽ICP备14008679号