近期论坛无法登录的解决方案


一亩三分地论坛

 找回密码
 获取更多干活,快来注册

一亩三分地官方iOS手机应用下载
查看: 784|回复: 3
收起左侧

Indeed OA 15

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

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

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

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

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.*;. 1point 3acres 璁哄潧
[size=100%][size=100%]
[size=100%]2

. From 1point 3acres bbs
[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]▾



[size=100%]public class Solution {
[size=100%][size=100%]
[size=100%]5
. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
[size=100%][size=100%][size=1.25em]▾
. 鍥磋鎴戜滑@1point 3 acres


[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


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


[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

. 1point3acres.com/bbs
[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
. visit 1point3acres.com for more.
. visit 1point3acres.com for more.
[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


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

.鐣欏璁哄潧-涓浜-涓夊垎鍦
[size=100%]        });. more info on 1point3acres.com
[size=100%][size=100%]
[size=100%]26


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


. 鍥磋鎴戜滑@1point 3 acres
[size=100%]        for (int i = 0; i < indexs.length; i++) {. 1point3acres.com/bbs
[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];. visit 1point3acres.com for more.
[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

.鏈枃鍘熷垱鑷1point3acres璁哄潧
[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.

[size=100%]            if (index < 0) index = -index-1;
[size=100%][size=100%]
[size=100%]38
. From 1point 3acres bbs

[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


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

[size=100%]        public Pair(int val, int count) {. 1point 3acres 璁哄潧
[size=100%][size=100%]
[size=100%]47

. 1point 3acres 璁哄潧
[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
. From 1point 3acres bbs
-google 1point3acres
[size=100%]}


 楼主| helloc93 发表于 2016-10-2 16:18:38 | 显示全部楼层
关注一亩三分地公众号:
Warald_一亩三分地
  1. 1.1point3acres缃

  2. import java.io.*;. more info on 1point3acres.com
  3. 2

  4. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  5. import java.util.*;
  6. 3

  7. . from: 1point3acres.com/bbs
  8. . 鍥磋鎴戜滑@1point 3 acres
  9. 4. Waral 鍗氬鏈夋洿澶氭枃绔,



  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 */. Waral 鍗氬鏈夋洿澶氭枃绔,
  15. 7.鏈枃鍘熷垱鑷1point3acres璁哄潧

  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

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

  28.         }
  29. 14
  30. . From 1point 3acres bbs
  31.         int[] res = calculate(pairs, Q);
  32. 15

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

  35.     }
  36. 17

  37. . From 1point 3acres bbs
  38. 18

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

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

  42.         if (pairs.length == 0 || Q < 2) return new int[0];
  43. 20. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷


  44. 21

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

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

  54.         });
  55. 26


  56. 27

  57.         int[] indexs = new int[pairs.length];
  58. 28

  59.         int sum = 1;
  60. 29-google 1point3acres



  61.         for (int i = 0; i < indexs.length; i++) {
  62. 30

  63.             indexs[i] = sum;. 1point 3acres 璁哄潧
  64. 31

  65.             sum += pairs[i].count;
  66. 32

  67.         }
  68. 33


  69. 34

  70.         int[] res = new int[Q-1];
  71. 35



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

  74.             int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  75. 37

  76.             if (index < 0) index = -index-1;
  77. 38

  78.             res[k-1] = pairs[index].val;
  79. 39

  80.         }
  81. 40. from: 1point3acres.com/bbs

  82.         return res;
  83. 41

  84.     }
  85. 42
  86. .1point3acres缃

  87. 43

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

  89.     static class Pair{
  90. 44

  91.         public int val = 0;
  92. 45

  93.         public int count = 0;
  94. 46



  95.         public Pair(int val, int count) {
  96. 47

  97.             this.val = val;
  98. 48

  99.             this.count = count;
  100. 49-google 1point3acres

  101.         }-google 1point3acres
  102. 50

  103.     }
  104. 51

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

使用道具 举报

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

使用道具 举报

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

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

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

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

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

  7. 4



  8. public class Solution {
  9. 5



  10.     public static void main(String args[] ) throws Exception {. 1point 3acres 璁哄潧
  11. 6

  12.         /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  13. 7. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴

  14.         Scanner sc = new Scanner(System.in);. visit 1point3acres.com for more.
  15. 8. From 1point 3acres bbs

  16.         int Q = sc.nextInt();
  17. 9
  18. . more info on 1point3acres.com
  19.         int M = sc.nextInt();
  20. 10

  21.         Pair[] pairs = new Pair[M];.1point3acres缃
  22. 11


  23. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  24.         for (int i = 0; i < M; i++) {
  25. 12. 1point3acres.com/bbs

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

  28.         }
  29. 14
  30. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  31.         int[] res = calculate(pairs, Q);
  32. 15

  33.         for (int n: res) System.out.println(n);
  34. 16
    . 1point3acres.com/bbs

  35.     }
  36. 17 鏉ユ簮涓浜.涓夊垎鍦拌鍧.


  37. 18


  38. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  39.     public static int[] calculate(Pair[] pairs, int Q) {
  40. 19.鐣欏璁哄潧-涓浜-涓夊垎鍦
  41. . 1point 3acres 璁哄潧
  42.         if (pairs.length == 0 || Q < 2) return new int[0];
  43. 20


  44. 21

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

  46.         Arrays.sort(pairs, new Comparator<Pair>(){
  47. 22. From 1point 3acres bbs



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

  50.                 return a.val-b.val;. 1point 3acres 璁哄潧
  51. 24

  52.             }. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  53. 25
  54. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  55.         });
  56. 26

  57. . more info on 1point3acres.com
  58. 27
  59. . 1point3acres.com/bbs
  60.         int[] indexs = new int[pairs.length];
  61. 28
  62. . From 1point 3acres bbs
  63.         int sum = 1;
  64. 29. 1point 3acres 璁哄潧

  65. . From 1point 3acres bbs

  66.         for (int i = 0; i < indexs.length; i++) {
  67. 30

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

  70.             sum += pairs[i].count;
  71. 32
  72. . 1point 3acres 璁哄潧
  73.         }
  74. 33 鏉ユ簮涓浜.涓夊垎鍦拌鍧.


  75. 34

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



  78.         for (int k = 1; k < Q; k++) {
  79. 36
  80. . Waral 鍗氬鏈夋洿澶氭枃绔,
  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;. 鍥磋鎴戜滑@1point 3 acres
  86. 39

  87.         }
  88. 40
  89. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  90.         return res;
  91. 41

  92.     }
  93. 42


  94. 43
  95. . visit 1point3acres.com for more.


  96.     static class Pair{
  97. 44
  98. -google 1point3acres
  99.         public int val = 0;
  100. 45

  101.         public int count = 0;
  102. 46.鏈枃鍘熷垱鑷1point3acres璁哄潧



  103.         public Pair(int val, int count) {
  104. 47
  105. . 1point3acres.com/bbs
  106.             this.val = val;. 1point 3acres 璁哄潧
  107. 48
  108. .1point3acres缃
  109.             this.count = count;
  110. 49

  111.         }. more info on 1point3acres.com
  112. 50

  113.     }
  114. 51

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

使用道具 举报

本版积分规则

关闭

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

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

custom counter

GMT+8, 2017-6-25 22:11

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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