亚麻OA求砸,面经神衣护体!


一亩三分地论坛

 找回密码
 Sign Up 注册获取更多干货
天天打游戏、照样领工资、还办H1B
这份工作你要不要?
把贵司招聘信息放这里
查看: 905|回复: 3
收起左侧

Indeed OA 15

[复制链接] |试试Instant~ |关注本帖
helloc93 发表于 2016-10-2 16:17:47 | 显示全部楼层 |阅读模式

2016(7-9月) 码农类 硕士 全职@Indeed - 内推 - 在线笔试 |Otherfresh grad应届毕业生

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看,没有帐号?Sign Up 注册获取更多干货

x
刚做的Indeed OA 15,挂了两个test case 4跟6,估计是挂了。附上写的代码,求大神帮忙debug。hackerrank不能看到test case是什么,真的很坑 085435d3g5fnijc5taicbr.png 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
[size=100%][size=100%]
[size=100%]1


[size=100%]import java.io.*;
[size=100%][size=100%]
[size=100%]2
. 1point 3acres 璁哄潧
鏉ユ簮涓浜.涓夊垎鍦拌鍧.
[size=100%]import java.util.*;
[size=100%][size=100%]
[size=100%]3


[size=100%]
[size=100%][size=100%]
[size=100%]4

[size=100%][size=100%][size=1.25em]▾

. 1point3acres.com/bbs

[size=100%]public class Solution {
[size=100%][size=100%]
[size=100%]5

[size=100%][size=100%][size=1.25em]▾



[size=100%]    public static void main(String args[] ) throws Exception {. From 1point 3acres bbs
[size=100%][size=100%]
[size=100%]6


[size=100%]        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
[size=100%][size=100%]
[size=100%]7


[size=100%]        Scanner sc = new Scanner(System.in);
[size=100%][size=100%]
[size=100%]8


[size=100%]        int Q = sc.nextInt();
[size=100%][size=100%]
[size=100%]9
. visit 1point3acres.com for more.

[size=100%]        int M = sc.nextInt();
[size=100%][size=100%]
[size=100%]10


[size=100%]        Pair[] pairs = new Pair[M];
[size=100%][size=100%]
[size=100%]11

. From 1point 3acres bbs[size=100%][size=100%][size=1.25em]▾


. more info on 1point3acres.com
[size=100%]        for (int i = 0; i < M; i++) {
[size=100%][size=100%]
[size=100%]12
. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴

[size=100%]            pairs = new Pair(sc.nextInt(), sc.nextInt());
[size=100%][size=100%]
[size=100%]13

.鐣欏璁哄潧-涓浜-涓夊垎鍦

[size=100%]        }
[size=100%][size=100%]
[size=100%]14
. Waral 鍗氬鏈夋洿澶氭枃绔,
. 鍥磋鎴戜滑@1point 3 acres
[size=100%]        int[] res = calculate(pairs, Q);
[size=100%][size=100%]
[size=100%]15


[size=100%]        for (int n: res) System.out.println(n);
[size=100%][size=100%]
[size=100%]16


[size=100%]    }
[size=100%][size=100%]
[size=100%]17


[size=100%]   
.鐣欏璁哄潧-涓浜-涓夊垎鍦[size=100%][size=100%]
[size=100%]18

[size=100%][size=100%][size=1.25em]▾
. 1point 3acres 璁哄潧


[size=100%]    public static int[] calculate(Pair[] pairs, int Q) {
[size=100%][size=100%]
[size=100%]19
. from: 1point3acres.com/bbs

[size=100%]        if (pairs.length == 0 || Q < 2) return new int[0];
[size=100%][size=100%]
[size=100%]20


[size=100%]        
[size=100%][size=100%]
[size=100%]21

[size=100%][size=100%][size=1.25em]▾



[size=100%]        Arrays.sort(pairs, new Comparator<Pair>(){
[size=100%][size=100%]
[size=100%]22
. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
[size=100%][size=100%][size=1.25em]▾



[size=100%]            public int compare(Pair a, Pair b) {
[size=100%][size=100%]
[size=100%]23

. more info on 1point3acres.com
[size=100%]                return a.val-b.val;
[size=100%][size=100%]
[size=100%]24


[size=100%]            }
[size=100%]
[size=100%]
[size=100%]25


[size=100%]        });
[size=100%][size=100%]
[size=100%]26


[size=100%]        . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
[size=100%][size=100%]
[size=100%]27

. 1point3acres.com/bbs
[size=100%]        int[] indexs = new int[pairs.length];. more info on 1point3acres.com
[size=100%][size=100%]
[size=100%]28


[size=100%]        int sum = 1;
[size=100%][size=100%]
[size=100%]29
. 鍥磋鎴戜滑@1point 3 acres
[size=100%][size=100%][size=1.25em]▾



[size=100%]        for (int i = 0; i < indexs.length; i++) {. 鍥磋鎴戜滑@1point 3 acres
[size=100%][size=100%]
[size=100%]30


[size=100%]            indexs = sum;-google 1point3acres
[size=100%][size=100%]
[size=100%]31


[size=100%]            sum += pairs.count;
[size=100%][size=100%]
[size=100%]32
-google 1point3acres
.1point3acres缃
[size=100%]        }
[size=100%][size=100%]
[size=100%]33
鏉ユ簮涓浜.涓夊垎鍦拌鍧.

[size=100%]        
[size=100%][size=100%]
[size=100%]34


[size=100%]        int[] res = new int[Q-1];. more info on 1point3acres.com
[size=100%][size=100%]
[size=100%]35

[size=100%][size=100%][size=1.25em]▾



[size=100%]        for (int k = 1; k < Q; k++) { 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
[size=100%][size=100%]
[size=100%]36
. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

[size=100%]            int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));
[size=100%][size=100%]
[size=100%]37


[size=100%]            if (index < 0) index = -index-1;
[size=100%][size=100%]
[size=100%]38

. Waral 鍗氬鏈夋洿澶氭枃绔,
[size=100%]            res[k-1] = pairs[index].val;
[size=100%][size=100%]
[size=100%]39


[size=100%]        }
[size=100%][size=100%]
[size=100%]40


[size=100%]        return res;
[size=100%][size=100%]
[size=100%]41


[size=100%]    }
[size=100%][size=100%]
[size=100%]42


[size=100%]   
[size=100%][size=100%]
[size=100%]43

[size=100%][size=100%][size=1.25em]▾



[size=100%]    static class Pair{
[size=100%][size=100%]
[size=100%]44

. more info on 1point3acres.com
[size=100%]        public int val = 0;
[size=100%][size=100%]
[size=100%]45


[size=100%]        public int count = 0;. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
[size=100%][size=100%]
[size=100%]46

[size=100%][size=100%][size=1.25em]▾

-google 1point3acres

[size=100%]        public Pair(int val, int count) {. 1point3acres.com/bbs
[size=100%][size=100%]
[size=100%]47
.1point3acres缃

[size=100%]            this.val = val;. from: 1point3acres.com/bbs
[size=100%][size=100%]
[size=100%]48


[size=100%]            this.count = count;
[size=100%][size=100%]
[size=100%]49


[size=100%]        }. From 1point 3acres bbs
[size=100%][size=100%]
[size=100%]50


[size=100%]    }
[size=100%][size=100%]
[size=100%]51


[size=100%]}


 楼主| helloc93 发表于 2016-10-2 16:18:38 | 显示全部楼层
  1. 1

  2. import java.io.*;
  3. 2

  4. import java.util.*;. 1point3acres.com/bbs
  5. 3


  6. . 1point3acres.com/bbs
  7. 4

  8. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.

  9. public class Solution {.鏈枃鍘熷垱鑷1point3acres璁哄潧
  10. 5. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴


  11. . from: 1point3acres.com/bbs
  12.     public static void main(String args[] ) throws Exception {. From 1point 3acres bbs
  13. 6

  14.         /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  15. 7

  16.         Scanner sc = new Scanner(System.in);
  17. 8. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

  18.         int Q = sc.nextInt();
  19. 9

  20.         int M = sc.nextInt();
  21. 10
  22. . Waral 鍗氬鏈夋洿澶氭枃绔,
  23.         Pair[] pairs = new Pair[M];
  24. 11



  25.         for (int i = 0; i < M; i++) {
  26. 12

  27.             pairs[i] = new Pair(sc.nextInt(), sc.nextInt());
  28. 13
  29. . 1point 3acres 璁哄潧
  30.         }.鐣欏璁哄潧-涓浜-涓夊垎鍦
  31. 14 鏉ユ簮涓浜.涓夊垎鍦拌鍧.

  32.         int[] res = calculate(pairs, Q);
  33. 15
  34. . 1point 3acres 璁哄潧
  35.         for (int n: res) System.out.println(n);
  36. 16

  37.     }
  38. 17


  39. 18. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  40. .鐣欏璁哄潧-涓浜-涓夊垎鍦

  41. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  42.     public static int[] calculate(Pair[] pairs, int Q) {
  43. 19. visit 1point3acres.com for more.
  44. . visit 1point3acres.com for more.
  45.         if (pairs.length == 0 || Q < 2) return new int[0];
  46. 20

  47. . 1point 3acres 璁哄潧
  48. 21
  49. . From 1point 3acres bbs


  50.         Arrays.sort(pairs, new Comparator<Pair>(){
  51. 22



  52.             public int compare(Pair a, Pair b) {
  53. 23

  54.                 return a.val-b.val;
  55. 24

  56.             }
  57. 25.鏈枃鍘熷垱鑷1point3acres璁哄潧

  58.         });
  59. 26
  60. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴

  61. . Waral 鍗氬鏈夋洿澶氭枃绔,
  62. 27

  63.         int[] indexs = new int[pairs.length];
  64. 28

  65.         int sum = 1;
  66. 29
  67. -google 1point3acres


  68.         for (int i = 0; i < indexs.length; i++) {
  69. 30

  70.             indexs[i] = sum;
  71. 31

  72.             sum += pairs[i].count;.1point3acres缃
  73. 32

  74.         }
  75. 33


  76. 34

  77.         int[] res = new int[Q-1];
  78. 35.鏈枃鍘熷垱鑷1point3acres璁哄潧



  79.         for (int k = 1; k < Q; k++) {. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  80. 36

  81.             int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));
  82. 37

  83.             if (index < 0) index = -index-1;. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  84. 38

  85.             res[k-1] = pairs[index].val;. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  86. 39

  87.         }
  88. 40

  89.         return res;
  90. 41

  91.     }
  92. 42


  93. 43



  94.     static class Pair{
  95. 44

  96.         public int val = 0;
  97. 45
  98. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  99.         public int count = 0;
  100. 46

  101. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.

  102.         public Pair(int val, int count) {
  103. 47. more info on 1point3acres.com
  104. . 1point 3acres 璁哄潧
  105.             this.val = val;
  106. 48

  107.             this.count = count;
  108. 49

  109.         }
  110. 50.1point3acres缃
  111. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  112.     }
  113. 51. 1point 3acres 璁哄潧

  114. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| helloc93 发表于 2016-10-2 16:19:16 | 显示全部楼层
第一次在帖子了插入代码,不会搞。。
回复 支持 反对

使用道具 举报

 楼主| helloc93 发表于 2016-10-2 16:19:51 | 显示全部楼层
一亩三分地严打"顶""好贴""收藏了"之类的垃圾回复帖!被警告三次,系统会自动封杀ID!

想支持楼主,请点击帖子下方的"好苗""分享""收藏"键,酌情给楼主加大米(系统不扣你自己的分)。. Waral 鍗氬鏈夋洿澶氭枃绔,
积分不够看不了帖子,请参考论坛导航里的"帮助","新手提纲"里有攒积分指南
  1. 1

  2. import java.io.*;
  3. 2. From 1point 3acres bbs

  4. import java.util.*;
  5. 3
    . 鍥磋鎴戜滑@1point 3 acres
  6. . visit 1point3acres.com for more.

  7. . visit 1point3acres.com for more.
  8. 4



  9. public class Solution {
  10. 5

  11. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

  12.     public static void main(String args[] ) throws Exception {-google 1point3acres
  13. 6

  14.         /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  15. 7
    . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

  16.         Scanner sc = new Scanner(System.in);
  17. 8

  18.         int Q = sc.nextInt();
  19. 9
  20. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  21.         int M = sc.nextInt();
  22. 10

  23.         Pair[] pairs = new Pair[M];
  24. 11



  25.         for (int i = 0; i < M; i++) {
  26. 12
  27. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  28.             pairs[i] = new Pair(sc.nextInt(), sc.nextInt());
    .1point3acres缃
  29. 13.鏈枃鍘熷垱鑷1point3acres璁哄潧

  30.         }
  31. 14
  32. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  33.         int[] res = calculate(pairs, Q);
  34. 15

  35.         for (int n: res) System.out.println(n);
  36. 16

  37.     }. from: 1point3acres.com/bbs
  38. 17


  39. 18. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴

  40. -google 1point3acres
  41. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  42.     public static int[] calculate(Pair[] pairs, int Q) {. more info on 1point3acres.com
  43. 19

  44.         if (pairs.length == 0 || Q < 2) return new int[0];. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  45. 20


  46. 21
  47. . visit 1point3acres.com for more.


  48.         Arrays.sort(pairs, new Comparator<Pair>(){ 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  49. 22

  50. . Waral 鍗氬鏈夋洿澶氭枃绔,
  51. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  52.             public int compare(Pair a, Pair b) {
  53. 23

  54.                 return a.val-b.val;
  55. 24

  56.             }
  57. 25

  58.         });. visit 1point3acres.com for more.
  59. 26


  60. 27

  61.         int[] indexs = new int[pairs.length];
  62. 28

  63.         int sum = 1;. 1point3acres.com/bbs
  64. 29


  65. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  66.         for (int i = 0; i < indexs.length; i++) {
  67. 30. From 1point 3acres bbs

  68.             indexs[i] = sum;
  69. 31

  70.             sum += pairs[i].count;
  71. 32

  72.         }
  73. 33. 鍥磋鎴戜滑@1point 3 acres

  74. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  75. 34

  76.         int[] res = new int[Q-1];
  77. 35



  78.         for (int k = 1; k < Q; k++) {
  79. 36

  80.             int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));
  81. 37.鏈枃鍘熷垱鑷1point3acres璁哄潧
  82. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  83.             if (index < 0) index = -index-1;. more info on 1point3acres.com
  84. 38

  85.             res[k-1] = pairs[index].val;
  86. 39

  87.         }. Waral 鍗氬鏈夋洿澶氭枃绔,
  88. 40. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

  89.         return res;
  90. 41

  91.     }
  92. 42


  93. 43



  94.     static class Pair{
  95. 44
  96. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  97.         public int val = 0;.鏈枃鍘熷垱鑷1point3acres璁哄潧
  98. 45
  99. . 1point3acres.com/bbs
  100.         public int count = 0;
  101. 46. 1point 3acres 璁哄潧

  102. . visit 1point3acres.com for more.
  103. . 鍥磋鎴戜滑@1point 3 acres
  104.         public Pair(int val, int count) {
  105. 47

  106.             this.val = val;
  107. 48 鏉ユ簮涓浜.涓夊垎鍦拌鍧.

  108.             this.count = count;
  109. 49

  110.         }
  111. 50

  112.     }. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  113. 51

  114. }
复制代码
回复 支持 反对

使用道具 举报

本版积分规则

关闭

一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明

custom counter

GMT+8, 2017-10-18 10:12

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

快速回复 返回顶部 返回列表