当前位置:   article > 正文

大疆前端笔试编程总结_大疆编程题

大疆编程题

B卷:

一、爱玩游戏的小J

大概意思:每一个游戏都有一个成就值和时间消耗,问在给定的时间内,小J最多能收获多少成就值

典型的01背包问题:

  1. import java.util.Scanner;
  2. public class xx {
  3. public static void main(String[] args) {
  4. Scanner sc = new Scanner(System.in);
  5. int t = sc.nextInt();
  6. while(t>0) {
  7. int n = sc.nextInt();
  8. int m = sc.nextInt();
  9. int v[] = new int[n+1];
  10. int w[] = new int[n+1];
  11. for (int i = 1; i < n+1; i++) {
  12. v[i] = sc.nextInt();
  13. w[i] = sc.nextInt();
  14. }
  15. int dp[][] = new int[n+1][m+1];
  16. for (int i = 1; i < n+1; i++) {
  17. for (int j = 1; j < m+1; j++) {
  18. if(w[i]>j) {
  19. dp[i][j] = dp[i-1][j];
  20. }else {
  21. dp[i][j] = Math.max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
  22. }
  23. }
  24. }
  25. System.out.println(dp[n][m]);
  26. t = t-1;
  27. }
  28. }
  29. }

二、不听话的机器人

根据给出的字符串指令,替换语句中的字符串

字符串替换,最简单一个:

  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Scanner sc = new Scanner(System.in);
  5. while (sc.hasNext()){
  6. int mapItem = sc.nextInt();
  7. int debugItem = sc.nextInt();
  8. String mapArray[][] = new String[mapItem][2];
  9. for (int i = 0; i < mapArray.length; i++) {
  10. for (int j = 0; j < mapArray[0].length; j++) {
  11. mapArray[i][j] = sc.next();
  12. }
  13. }
  14. String inputArray[] = new String[debugItem];
  15. for (int i = 0; i < inputArray.length; i++) {
  16. inputArray[i]= sc.next();
  17. }
  18. for (int i = 0; i < inputArray.length; i++) {
  19. for (int j = 0; j < mapArray.length; j++) {
  20. if (inputArray[i].equals(mapArray[j][0])){
  21. System.out.println(mapArray[j][1]);
  22. }
  23. }
  24. }
  25. }
  26. }
  27. }

三、应该怎么吃

大概意思:有很多零食,问正好花掉X元的情况下,有多少种吃法,其中这个人对每个零食的喜爱程度不一样,喜爱程度高的零食必须多余比它喜爱程度低的零食个数要多,问有多少种情况,最终结果可能很大,要求结果%10000007

没时间写了,时间要求三秒,感觉可以暴力试一下~

听说A卷是一道基础编程,一道动态规划,一道最短路径,感觉A卷难度适中,B卷最后一题思路不清,前两个简单。

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

闽ICP备14008679号