一亩三分地论坛

 找回密码
 Sign Up 注册获取更多干货
码农求职神器Triplebyte:
不用海投,内推你去多家公司面试
Airbnb 数据科学职位
in analytics and inference
天天打游戏、照样领工资,
你要不要来?
把贵司招聘信息放这里
查看: 981|回复: 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


[size=100%]import java.util.*;
[size=100%][size=100%]
[size=100%]3

. Waral 鍗氬鏈夋洿澶氭枃绔,
[size=100%]. 1point3acres.com/bbs
[size=100%][size=100%]
[size=100%]4

[size=100%][size=100%][size=1.25em]▾
鏉ユ簮涓浜.涓夊垎鍦拌鍧.

. more info on 1point3acres.com
[size=100%]public class Solution {
[size=100%][size=100%]
[size=100%]5

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


. 1point3acres.com/bbs
[size=100%]    public static void main(String args[] ) throws Exception {
[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

. 鍥磋鎴戜滑@1point 3 acres
[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

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



[size=100%]        for (int i = 0; i < M; i++) {. From 1point 3acres bbs
[size=100%][size=100%]
[size=100%]12


[size=100%]            pairs = new Pair(sc.nextInt(), sc.nextInt());. Waral 鍗氬鏈夋洿澶氭枃绔,
[size=100%][size=100%]
[size=100%]13


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

. Waral 鍗氬鏈夋洿澶氭枃绔,
[size=100%]        int[] res = calculate(pairs, Q);
[size=100%][size=100%]
[size=100%]15

. visit 1point3acres.com for more.
. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
[size=100%]        for (int n: res) System.out.println(n);. from: 1point3acres.com/bbs
[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]▾



[size=100%]    public static int[] calculate(Pair[] pairs, int Q) {
[size=100%][size=100%]
[size=100%]19
. visit 1point3acres.com for more.

[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]▾
. 鍥磋鎴戜滑@1point 3 acres


[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


. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴[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

. From 1point 3acres bbs
[size=100%]        int[] indexs = new int[pairs.length];
[size=100%][size=100%]
[size=100%]28


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

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



[size=100%]        for (int i = 0; i < indexs.length; i++) {. 1point 3acres 璁哄潧
[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%]        }. more info on 1point3acres.com
[size=100%][size=100%]
[size=100%]33
. Waral 鍗氬鏈夋洿澶氭枃绔,
. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
[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


[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

.1point3acres缃
[size=100%]        }
[size=100%][size=100%]
[size=100%]40


[size=100%]        return res;
[size=100%][size=100%]
[size=100%]41
. from: 1point3acres.com/bbs

[size=100%]    }. more info on 1point3acres.com
[size=100%][size=100%]
[size=100%]42

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

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

. more info on 1point3acres.com

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


[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]▾



[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


[size=100%]        }. 1point 3acres 璁哄潧
[size=100%][size=100%]
[size=100%]50


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


[size=100%]}

. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
 楼主| helloc93 发表于 2016-10-2 16:18:38 | 显示全部楼层
  1. 1

  2. import java.io.*;. 鍥磋鎴戜滑@1point 3 acres
  3. 2

  4. import java.util.*;
  5. 3. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

  6. . from: 1point3acres.com/bbs

  7. 4



  8. public class Solution {. 1point3acres.com/bbs
  9. 5



  10.     public static void main(String args[] ) throws Exception {
  11. 6
  12. .1point3acres缃
  13.         /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  14. 7

  15.         Scanner sc = new Scanner(System.in);
  16. 8
  17. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  18.         int Q = sc.nextInt();
  19. 9

  20.         int M = sc.nextInt();. visit 1point3acres.com for more.
  21. 10

  22.         Pair[] pairs = new Pair[M];. Waral 鍗氬鏈夋洿澶氭枃绔,
  23. 11
  24. . Waral 鍗氬鏈夋洿澶氭枃绔,


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

  27.             pairs[i] = new Pair(sc.nextInt(), sc.nextInt());
  28. 13

  29.         }
  30. 14

  31.         int[] res = calculate(pairs, Q);
  32. 15

  33.         for (int n: res) System.out.println(n);
  34. 16

  35.     }
  36. 17. 鍥磋鎴戜滑@1point 3 acres


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


  39.     public static int[] calculate(Pair[] pairs, int Q) {
  40. 19
  41. -google 1point3acres
  42.         if (pairs.length == 0 || Q < 2) return new int[0];.1point3acres缃
  43. 20-google 1point3acres
  44. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  45. . from: 1point3acres.com/bbs
  46. 21



  47.         Arrays.sort(pairs, new Comparator<Pair>(){
  48. 22
  49. .鐣欏璁哄潧-涓浜-涓夊垎鍦


  50.             public int compare(Pair a, Pair b) {
  51. 23
  52. . Waral 鍗氬鏈夋洿澶氭枃绔,
  53.                 return a.val-b.val;
  54. 24
  55. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  56.             }
  57. 25. 1point3acres.com/bbs

  58.         });
  59. 26
  60. . 1point 3acres 璁哄潧

  61. 27

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

  64.         int sum = 1;. Waral 鍗氬鏈夋洿澶氭枃绔,
  65. 29



  66.         for (int i = 0; i < indexs.length; i++) {
  67. 30
  68. . From 1point 3acres bbs
  69.             indexs[i] = sum;
  70. 31

  71.             sum += pairs[i].count;
  72. 32
  73. -google 1point3acres
  74.         }
  75. 33
  76. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

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

  78.         int[] res = new int[Q-1];
  79. 35
  80. . visit 1point3acres.com for more.


  81.         for (int k = 1; k < Q; k++) {
  82. 36
    .鏈枃鍘熷垱鑷1point3acres璁哄潧

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

  85.             if (index < 0) index = -index-1;
  86. 38
  87. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  88.             res[k-1] = pairs[index].val;
  89. 39

  90.         }
  91. 40
  92. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  93.         return res;. from: 1point3acres.com/bbs
  94. 41

  95.     }
  96. 42


  97. 43



  98.     static class Pair{
  99. 44

  100.         public int val = 0;
  101. 45

  102.         public int count = 0;
  103. 46


  104. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  105.         public Pair(int val, int count) {
  106. 47

  107.             this.val = val;
  108. 48

  109.             this.count = count;
  110. 49

  111.         }
  112. 50

  113.     }. From 1point 3acres bbs
  114. 51
  115. . visit 1point3acres.com for more.
  116. }
复制代码
回复 支持 反对

使用道具 举报

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

使用道具 举报

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

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

  2. import java.io.*;
  3. 2. 1point3acres.com/bbs

  4. import java.util.*;
  5. 3

  6. -google 1point3acres
  7. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  8. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  9. 4
  10. . 1point3acres.com/bbs


  11. public class Solution {
  12. 5



  13.     public static void main(String args[] ) throws Exception {
  14. 6. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴

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

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

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

  21.         int M = sc.nextInt();
  22. 10

  23.         Pair[] pairs = new Pair[M];
  24. 11
  25. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴


  26.         for (int i = 0; i < M; i++) { 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  27. 12

  28.             pairs[i] = new Pair(sc.nextInt(), sc.nextInt());
  29. 13

  30.         }
  31. 14.鐣欏璁哄潧-涓浜-涓夊垎鍦

  32.         int[] res = calculate(pairs, Q);
  33. 15
  34. -google 1point3acres
  35.         for (int n: res) System.out.println(n);
  36. 16

  37. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  38.     }
  39. 17


  40. 18



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

  43.         if (pairs.length == 0 || Q < 2) return new int[0];
  44. 20


  45. 21



  46.         Arrays.sort(pairs, new Comparator<Pair>(){. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  47. 22



  48.             public int compare(Pair a, Pair b) {
  49. 23

  50.                 return a.val-b.val;
  51. 24

  52.             }. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  53. 25. From 1point 3acres bbs

  54.         });
  55. 26

  56. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  57. 27

  58.         int[] indexs = new int[pairs.length];
  59. 28
  60. . 1point 3acres 璁哄潧
  61.         int sum = 1;
  62. 29

  63. . visit 1point3acres.com for more.

  64.         for (int i = 0; i < indexs.length; i++) {. Waral 鍗氬鏈夋洿澶氭枃绔,
  65. 30

  66.             indexs[i] = sum;
  67. 31

  68.             sum += pairs[i].count;
  69. 32

  70.         }
  71. 33


  72. 34

  73.         int[] res = new int[Q-1];
  74. 35



  75.         for (int k = 1; k < Q; k++) {
  76. 36. visit 1point3acres.com for more.

  77.             int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  78. 37
  79. . 1point3acres.com/bbs
  80.             if (index < 0) index = -index-1;
  81. 38. from: 1point3acres.com/bbs

  82.             res[k-1] = pairs[index].val;
  83. 39

  84. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  85.         } 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  86. 40

  87.         return res;
  88. 41

  89.     }. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  90. 42


  91. 43



  92.     static class Pair{. from: 1point3acres.com/bbs
  93. 44

  94.         public int val = 0;
  95. 45

  96.         public int count = 0;
  97. 46
  98. -google 1point3acres

  99. . visit 1point3acres.com for more.

  100.         public Pair(int val, int count) {
  101. 47
  102. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  103.             this.val = val;
  104. 48. Waral 鍗氬鏈夋洿澶氭枃绔,

  105.             this.count = count;.鐣欏璁哄潧-涓浜-涓夊垎鍦
  106. 49. from: 1point3acres.com/bbs

  107.         }
  108. 50
  109. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  110.     }
  111. 51

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

使用道具 举报

本版积分规则

关闭

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

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

custom counter

GMT+8, 2017-12-12 16:45

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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