一亩三分地论坛

 找回密码
 Sign Up 注册获取更多干货
码农求职神器Triplebyte:
不用海投,内推多家公司面试
游戏初创公司
招聘工程师、Designer和游戏策划
游戏初创公司DreamCraft招聘工程师、UIUX Designer和游戏策划
把贵司招聘信息放这里
查看: 1053|回复: 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
. Waral 鍗氬鏈夋洿澶氭枃绔,

[size=100%]import java.io.*;
[size=100%][size=100%]
[size=100%]2


[size=100%]import java.util.*;
[size=100%][size=100%]
[size=100%]3
. From 1point 3acres bbs

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

[size=100%][size=100%][size=1.25em]▾
. visit 1point3acres.com for more.


[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 {. more info on 1point3acres.com
[size=100%][size=100%]
[size=100%]6

. more info on 1point3acres.com
[size=100%]        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
[size=100%][size=100%]
[size=100%]7
. more info on 1point3acres.com
.1point3acres缃
[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


[size=100%]        int M = sc.nextInt();. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
[size=100%][size=100%]
[size=100%]10


[size=100%]        Pair[] pairs = new Pair[M];. 1point3acres.com/bbs
[size=100%][size=100%]
[size=100%]11

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


.鏈枃鍘熷垱鑷1point3acres璁哄潧
[size=100%]        for (int i = 0; i < M; i++) {
[size=100%][size=100%]
[size=100%]12
. From 1point 3acres bbs

[size=100%]            pairs = new Pair(sc.nextInt(), sc.nextInt());.1point3acres缃
[size=100%][size=100%]
[size=100%]13
. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴

[size=100%]        }
[size=100%][size=100%]
[size=100%]14


[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%]    .鏈枃鍘熷垱鑷1point3acres璁哄潧
[size=100%][size=100%]
[size=100%]18

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

. From 1point 3acres bbs

[size=100%]    public static int[] calculate(Pair[] pairs, int Q) {
[size=100%][size=100%]
[size=100%]19


[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


[size=100%]                return a.val-b.val;. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
[size=100%][size=100%]
[size=100%]24

.1point3acres缃
[size=100%]            }
[size=100%]. From 1point 3acres bbs
[size=100%]
[size=100%]25

.鏈枃鍘熷垱鑷1point3acres璁哄潧
[size=100%]        });
[size=100%][size=100%]
[size=100%]26
. Waral 鍗氬鏈夋洿澶氭枃绔,
. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
[size=100%]        
[size=100%][size=100%]
[size=100%]27


[size=100%]        int[] indexs = new int[pairs.length];
[size=100%][size=100%]
[size=100%]28

. From 1point 3acres bbs
[size=100%]        int sum = 1;. more info on 1point3acres.com
[size=100%][size=100%]
[size=100%]29

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



[size=100%]        for (int i = 0; i < indexs.length; i++) {
[size=100%][size=100%]
[size=100%]30


[size=100%]            indexs = sum;
[size=100%][size=100%]
[size=100%]31


[size=100%]            sum += pairs.count;. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
[size=100%][size=100%]
[size=100%]32


[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];. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
[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
. visit 1point3acres.com for more.
. From 1point 3acres bbs
[size=100%]            if (index < 0) index = -index-1;
[size=100%][size=100%]
[size=100%]38


[size=100%]            res[k-1] = pairs[index].val;
[size=100%][size=100%]
[size=100%]39


-google 1point3acres[size=100%]        }
[size=100%][size=100%]
[size=100%]40


[size=100%]        return res;. from: 1point3acres.com/bbs
[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]▾

.1point3acres缃

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

.1point3acres缃
[size=100%]        public int val = 0;
[size=100%][size=100%]
[size=100%]45

.1point3acres缃
[size=100%]        public int count = 0;
[size=100%][size=100%]
[size=100%]46

[size=100%][size=100%][size=1.25em]▾
. visit 1point3acres.com for more.

. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
[size=100%]        public Pair(int val, int count) {
[size=100%][size=100%]
[size=100%]47


[size=100%]            this.val = val;
[size=100%][size=100%]
[size=100%]48


[size=100%]            this.count = count;
[size=100%][size=100%]
[size=100%]49
. visit 1point3acres.com for more.

[size=100%]        }
[size=100%][size=100%]
[size=100%]50


[size=100%]    }
[size=100%][size=100%]
[size=100%]51
. From 1point 3acres bbs
. more info on 1point3acres.com
[size=100%]}
.鐣欏璁哄潧-涓浜-涓夊垎鍦

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

  2. import java.io.*;. visit 1point3acres.com for more.
  3. 2
  4. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  5. import java.util.*;
  6. 3

  7. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  8. . more info on 1point3acres.com
  9. 4



  10. public class Solution {
  11. 5



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

  14.         /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  15. 7
  16. . 1point3acres.com/bbs
  17.         Scanner sc = new Scanner(System.in);
    .鐣欏璁哄潧-涓浜-涓夊垎鍦
  18. 8

  19.         int Q = sc.nextInt();
  20. 9
  21. .1point3acres缃
  22.         int M = sc.nextInt();
  23. 10

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

  26. . 1point 3acres 璁哄潧

  27.         for (int i = 0; i < M; i++) {
  28. 12

  29.             pairs[i] = new Pair(sc.nextInt(), sc.nextInt());
  30. 13
  31. .1point3acres缃
  32.         }. From 1point 3acres bbs
  33. 14
  34. .1point3acres缃
  35.         int[] res = calculate(pairs, Q);
  36. 15

  37.         for (int n: res) System.out.println(n);. 1point 3acres 璁哄潧
  38. 16

  39.     }
  40. 17


  41. 18. Waral 鍗氬鏈夋洿澶氭枃绔,



  42.     public static int[] calculate(Pair[] pairs, int Q) {
  43. 19

  44.         if (pairs.length == 0 || Q < 2) return new int[0];. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  45. 20

  46. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  47. 21
  48. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  49. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴

  50.         Arrays.sort(pairs, new Comparator<Pair>(){.鐣欏璁哄潧-涓浜-涓夊垎鍦
  51. 22.鏈枃鍘熷垱鑷1point3acres璁哄潧



  52. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  53.             public int compare(Pair a, Pair b) {
  54. 23

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

  57.             }
  58. 25

  59.         });
  60. 26

  61. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  62. 27
  63. . visit 1point3acres.com for more.
  64.         int[] indexs = new int[pairs.length];
  65. 28
  66. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  67.         int sum = 1;
  68. 29



  69.         for (int i = 0; i < indexs.length; i++) {
  70. 30. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

  71.             indexs[i] = sum;
  72. 31
  73. . 1point3acres.com/bbs
  74.             sum += pairs[i].count;
  75. 32
  76. . from: 1point3acres.com/bbs
  77.         }
  78. 33.鏈枃鍘熷垱鑷1point3acres璁哄潧


  79. 34

  80.         int[] res = new int[Q-1];
  81. 35

  82. . 鍥磋鎴戜滑@1point 3 acres

  83.         for (int k = 1; k < Q; k++) {
  84. 36
  85. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  86.             int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));
  87. 37
    . more info on 1point3acres.com
  88. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  89.             if (index < 0) index = -index-1;
  90. 38
  91. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  92.             res[k-1] = pairs[index].val;
  93. 39

  94.         }
  95. 40

  96.         return res;
  97. 41. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

  98.     }
  99. 42


  100. 43


  101. . Waral 鍗氬鏈夋洿澶氭枃绔,
  102.     static class Pair{
  103. 44

  104.         public int val = 0;. From 1point 3acres bbs
  105. 45
  106. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  107.         public int count = 0;. visit 1point3acres.com for more.
  108. 46
  109. . 1point3acres.com/bbs


  110.         public Pair(int val, int count) {
  111. 47

  112.             this.val = val;
  113. 48

  114.             this.count = count;. more info on 1point3acres.com
  115. 49

  116.         }-google 1point3acres
  117. 50
  118. . 1point 3acres 璁哄潧
  119.     }
  120. 51
  121. .1point3acres缃
  122. }
复制代码
回复 支持 反对

使用道具 举报

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

使用道具 举报

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

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

  5. import java.util.*;
  6. 3. 鍥磋鎴戜滑@1point 3 acres
  7. . 1point 3acres 璁哄潧


  8. 4

  9. . from: 1point3acres.com/bbs


  10. public class Solution {. from: 1point3acres.com/bbs
  11. 5



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

  14.         /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  15. 7
  16. .1point3acres缃
  17.         Scanner sc = new Scanner(System.in);
  18. 8

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

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


  26. . Waral 鍗氬鏈夋洿澶氭枃绔,
  27.         for (int i = 0; i < M; i++) {
  28. 12

  29.             pairs[i] = new Pair(sc.nextInt(), sc.nextInt());. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  30. 13

  31.         }
  32. 14
  33. -google 1point3acres
  34.         int[] res = calculate(pairs, Q);
  35. 15

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

  38.     }.鏈枃鍘熷垱鑷1point3acres璁哄潧
  39. 17


  40. 18
  41. . From 1point 3acres bbs


  42.     public static int[] calculate(Pair[] pairs, int Q) {
  43. 19

  44.         if (pairs.length == 0 || Q < 2) return new int[0];. from: 1point3acres.com/bbs
  45. 20


  46. 21
  47. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  48. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴

  49.         Arrays.sort(pairs, new Comparator<Pair>(){
  50. 22
    .鐣欏璁哄潧-涓浜-涓夊垎鍦
  51. .鏈枃鍘熷垱鑷1point3acres璁哄潧

  52. . From 1point 3acres bbs
  53.             public int compare(Pair a, Pair b) {. 鍥磋鎴戜滑@1point 3 acres
  54. 23

  55.                 return a.val-b.val;.1point3acres缃
  56. 24

  57.             }
  58. 25
  59. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  60.         });
  61. 26


  62. 27
  63. . From 1point 3acres bbs
  64.         int[] indexs = new int[pairs.length];
  65. 28

  66.         int sum = 1;
  67. 29. visit 1point3acres.com for more.



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

  70.             indexs[i] = sum;
    . Waral 鍗氬鏈夋洿澶氭枃绔,
  71. 31

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

  74.         }
  75. 33. 鍥磋鎴戜滑@1point 3 acres


  76. 34

  77.         int[] res = new int[Q-1];. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  78. 35



  79.         for (int k = 1; k < Q; k++) {
  80. 36
  81. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  82.             int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));
  83. 37. 1point3acres.com/bbs

  84.             if (index < 0) index = -index-1;
  85. 38

  86.             res[k-1] = pairs[index].val;
  87. 39. 鍥磋鎴戜滑@1point 3 acres

  88.         }
  89. 40

  90.         return res;
  91. 41
  92. . Waral 鍗氬鏈夋洿澶氭枃绔,
  93.     }. 鍥磋鎴戜滑@1point 3 acres
  94. 42


  95. 43



  96.     static class Pair{
  97. 44

  98.         public int val = 0;
  99. 45 鏉ユ簮涓浜.涓夊垎鍦拌鍧.

  100.         public int count = 0;. from: 1point3acres.com/bbs
  101. 46.1point3acres缃



  102.         public Pair(int val, int count) {
  103. 47

  104.             this.val = val;
  105. 48

  106.             this.count = count;
  107. 49

  108.         }
  109. 50

  110.     }
  111. 51
  112. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  113. }
复制代码
回复 支持 反对

使用道具 举报

本版积分规则

关闭

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

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

custom counter

GMT+8, 2018-2-21 17:29

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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