一亩三分地论坛

 找回密码
 获取更多干货,去instant注册!

扫码关注一亩三分地公众号
查看: 303|回复: 3
收起左侧

Indeed OA 15

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

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

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

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

x
刚做的Indeed OA 15,挂了两个test case 4跟6,估计是挂了。附上写的代码,求大神帮忙debug。hackerrank不能看到test case是什么,真的很坑 085435d3g5fnijc5taicbr.png
[size=100%][size=100%]
[size=100%]1
. from: 1point3acres.com/bbs

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


[size=100%]import java.util.*;-google 1point3acres
[size=100%][size=100%]
[size=100%]3

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

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


. from: 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 {. 1point 3acres 璁哄潧
[size=100%][size=100%]
[size=100%]6

. 鍥磋鎴戜滑@1point 3 acres
[size=100%]        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
[size=100%][size=100%]
[size=100%]7
.1point3acres缃

[size=100%]        Scanner sc = new Scanner(System.in);.鐣欏璁哄潧-涓浜-涓夊垎鍦
[size=100%][size=100%]
[size=100%]8

. 鍥磋鎴戜滑@1point 3 acres
鏉ユ簮涓浜.涓夊垎鍦拌鍧.
[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


. Waral 鍗氬鏈夋洿澶氭枃绔,[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++) {
[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%]        }. Waral 鍗氬鏈夋洿澶氭枃绔,
[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%]   
[size=100%][size=100%]
[size=100%]18

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



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


[size=100%]        if (pairs.length == 0 || Q < 2) return new int[0];. visit 1point3acres.com for more.
[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
-google 1point3acres

[size=100%]            }. From 1point 3acres bbs
[size=100%]
[size=100%]
[size=100%]25
. 1point 3acres 璁哄潧

[size=100%]        });.鏈枃鍘熷垱鑷1point3acres璁哄潧
[size=100%][size=100%]
[size=100%]26

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


[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++) {
[size=100%][size=100%]
[size=100%]30
. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴

[size=100%]            indexs = sum;. 鍥磋鎴戜滑@1point 3 acres
[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


[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
. more info on 1point3acres.com

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

. Waral 鍗氬鏈夋洿澶氭枃绔,
[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


[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%]    . Waral 鍗氬鏈夋洿澶氭枃绔,
[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


[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
. 1point 3acres 璁哄潧
[size=100%][size=100%][size=1.25em]▾



[size=100%]        public Pair(int val, int count) {. more info on 1point3acres.com
[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%]        }
[size=100%][size=100%]
[size=100%]50


[size=100%]    }
[size=100%][size=100%]
[size=100%]51
.鏈枃鍘熷垱鑷1point3acres璁哄潧

[size=100%]}.鏈枃鍘熷垱鑷1point3acres璁哄潧


 楼主| helloc93 发表于 2016-10-2 16:18:38 | 显示全部楼层
  1. 1
  2. .1point3acres缃
  3. import java.io.*;
  4. 2

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



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


  9. public class Solution {
  10. 5



  11.     public static void main(String args[] ) throws Exception { 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  12. 6
  13. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  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.         Pair[] pairs = new Pair[M];
  23. 11



  24.         for (int i = 0; i < M; i++) {
  25. 12. from: 1point3acres.com/bbs

  26.             pairs[i] = new Pair(sc.nextInt(), sc.nextInt());
  27. 13. more info on 1point3acres.com

  28.         }. 1point 3acres 璁哄潧
  29. 14

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

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

  34.     }
  35. 17


  36. 18



  37.     public static int[] calculate(Pair[] pairs, int Q) {
  38. 19

  39.         if (pairs.length == 0 || Q < 2) return new int[0];
  40. 20.鏈枃鍘熷垱鑷1point3acres璁哄潧


  41. 21

  42. . 1point3acres.com/bbs

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



  45.             public int compare(Pair a, Pair b) {
  46. 23

  47.                 return a.val-b.val;
  48. 24

  49.             }
  50. 25

  51.         });
  52. 26.鐣欏璁哄潧-涓浜-涓夊垎鍦
  53. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴

  54. 27

  55.         int[] indexs = new int[pairs.length];
  56. 28

  57.         int sum = 1;
  58. 29



  59.         for (int i = 0; i < indexs.length; i++) {
  60. 30

  61.             indexs[i] = sum;
  62. 31
  63. . 1point 3acres 璁哄潧
  64.             sum += pairs[i].count;
  65. 32
  66. -google 1point3acres
  67.         }
  68. 33


  69. 34
  70. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  71.         int[] res = new int[Q-1];
  72. 35.1point3acres缃



  73.         for (int k = 1; k < Q; k++) {
  74. 36

  75.             int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));
  76. 37
  77. . visit 1point3acres.com for more.
  78.             if (index < 0) index = -index-1;
  79. 38.鏈枃鍘熷垱鑷1point3acres璁哄潧
  80. -google 1point3acres
  81.             res[k-1] = pairs[index].val;
  82. 39

  83.         }
  84. 40
  85. . more info on 1point3acres.com
  86.         return res;
  87. 41. From 1point 3acres bbs
  88. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  89.     }
  90. 42
  91. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴

  92. 43

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

  94.     static class Pair{
  95. 44

  96.         public int val = 0;
  97. 45

  98.         public int count = 0; 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  99. 46.1point3acres缃

  100. . from: 1point3acres.com/bbs

  101.         public Pair(int val, int count) {
    . Waral 鍗氬鏈夋洿澶氭枃绔,
  102. 47

  103.             this.val = val;
  104. 48-google 1point3acres

  105.             this.count = count;
  106. 49
  107. -google 1point3acres
  108.         }
  109. 50
  110. . from: 1point3acres.com/bbs
  111.     }
  112. 51
  113. . From 1point 3acres bbs
  114. }
复制代码
回复 支持 反对

使用道具 举报

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

使用道具 举报

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

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

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

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



  6. 4



  7. public class Solution {
  8. 5



  9. . visit 1point3acres.com for more.
  10.     public static void main(String args[] ) throws Exception {
  11. 6. from: 1point3acres.com/bbs

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

  14.         Scanner sc = new Scanner(System.in);
  15. 8
  16. .1point3acres缃
  17.         int Q = sc.nextInt();
  18. 9

  19.         int M = sc.nextInt();
  20. 10

  21.         Pair[] pairs = new Pair[M];
  22. 11
  23. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

  24. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴

  25.         for (int i = 0; i < M; i++) {
  26. 12. more info on 1point3acres.com

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

  29.         }. visit 1point3acres.com for more.
  30. 14.鐣欏璁哄潧-涓浜-涓夊垎鍦

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

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

  35.     }
  36. 17.鐣欏璁哄潧-涓浜-涓夊垎鍦


  37. 18


  38. . 1point3acres.com/bbs
  39.     public static int[] calculate(Pair[] pairs, int Q) {
  40. 19

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

  44. 21.鏈枃鍘熷垱鑷1point3acres璁哄潧

  45. -google 1point3acres

  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. . From 1point 3acres bbs
  53.             }
  54. 25

  55.         });
  56. 26
  57. . 1point 3acres 璁哄潧

  58. 27

  59.         int[] indexs = new int[pairs.length];
  60. 28. more info on 1point3acres.com

  61.         int sum = 1;. From 1point 3acres bbs
  62. 29
  63. . more info on 1point3acres.com

  64. . 鍥磋鎴戜滑@1point 3 acres
  65.         for (int i = 0; i < indexs.length; i++) {
  66. 30. 1point 3acres 璁哄潧
  67. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  68.             indexs[i] = sum;
  69. 31
  70. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  71.             sum += pairs[i].count;
  72. 32
  73. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  74.         }
  75. 33. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴


  76. 34

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



  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. Waral 鍗氬鏈夋洿澶氭枃绔,

  87.         }
  88. 40

  89.         return res;. 1point3acres.com/bbs
  90. 41

  91.     }
  92. 42. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷


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

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

  95.     static class Pair{
  96. 44. 鍥磋鎴戜滑@1point 3 acres

  97.         public int val = 0;
  98. 45

  99.         public int count = 0;
  100. 46



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

  103.             this.val = val;
  104. 48

  105.             this.count = count;
  106. 49
  107. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  108.         }
  109. 50

  110.     }
  111. 51

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

使用道具 举报

本版积分规则

请点这里访问我们的新网站:一亩三分地Instant.

Instant搜索更强大,不扣积分,内容组织的更好更整洁!目前仍在beta版本,努力完善中!反馈请点这里

关闭

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

手机版|小黑屋|一亩三分地论坛声明 ( 沪ICP备11015994号 )

custom counter

GMT+8, 2016-12-3 23:52

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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