May 2009 - May 2017 论坛八周年-你的足迹,我的骄傲


一亩三分地论坛

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

一亩三分地官方iOS手机应用下载
查看: 736|回复: 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 .鏈枃鍘熷垱鑷1point3acres璁哄潧
[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


[size=100%]. 鍥磋鎴戜滑@1point 3 acres
[size=100%][size=100%]
[size=100%]4

[size=100%][size=100%][size=1.25em]▾
-google 1point3acres

.鏈枃鍘熷垱鑷1point3acres璁哄潧
[size=100%]public class Solution {
[size=100%][size=100%]
[size=100%]5

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

. visit 1point3acres.com for more.

[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
. from: 1point3acres.com/bbs

[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

.1point3acres缃
[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

-google 1point3acres

[size=100%]            pairs = new Pair(sc.nextInt(), sc.nextInt());
[size=100%][size=100%]
[size=100%]13
. 1point 3acres 璁哄潧

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

[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
. more info on 1point3acres.com
. Waral 鍗氬鏈夋洿澶氭枃绔,
[size=100%]        
[size=100%][size=100%]
[size=100%]21
.鐣欏璁哄潧-涓浜-涓夊垎鍦
[size=100%][size=100%][size=1.25em]▾



[size=100%]        Arrays.sort(pairs, new Comparator<Pair>(){. more info on 1point3acres.com
[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

. From 1point 3acres bbs
[size=100%]                return a.val-b.val;
[size=100%][size=100%]
[size=100%]24


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


[size=100%]        });. 鍥磋鎴戜滑@1point 3 acres
[size=100%][size=100%]
[size=100%]26


[size=100%]        
[size=100%][size=100%]
[size=100%]27
-google 1point3acres

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

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

. from: 1point3acres.com/bbs [size=100%]            sum += pairs.count;
[size=100%][size=100%]
[size=100%]32
. from: 1point3acres.com/bbs

[size=100%]        }. 1point3acres.com/bbs
[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


[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%]    -google 1point3acres
[size=100%][size=100%]
[size=100%]43
.1point3acres缃
[size=100%][size=100%][size=1.25em]▾



[size=100%]    static class Pair{
[size=100%][size=100%]
[size=100%]44
. visit 1point3acres.com for more.
. From 1point 3acres bbs
[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 3 acres
[size=100%][size=100%]
[size=100%]50


[size=100%]    }
[size=100%][size=100%]
[size=100%]51
. 1point3acres.com/bbs

[size=100%]}. Waral 鍗氬鏈夋洿澶氭枃绔,


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

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

  4. import java.util.*;. From 1point 3acres bbs
  5. 3



  6. 4



  7. public class Solution {
  8. 5. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷



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

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

  13.         Scanner sc = new Scanner(System.in);
  14. 8

  15.         int Q = sc.nextInt();
  16. 9

  17.         int M = sc.nextInt();
  18. 10-google 1point3acres
  19. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  20.         Pair[] pairs = new Pair[M];
  21. 11. more info on 1point3acres.com

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

  23.         for (int i = 0; i < M; i++) {
  24. 12

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

  27.         }
  28. 14

  29.         int[] res = calculate(pairs, Q);-google 1point3acres
  30. 15
  31. . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
  32.         for (int n: res) System.out.println(n);
  33. 16
  34. . 鍥磋鎴戜滑@1point 3 acres
  35.     }
  36. 17
  37. .1point3acres缃

  38. 18

  39. . visit 1point3acres.com for more.

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

  42.         if (pairs.length == 0 || Q < 2) return new int[0];
  43. 20. visit 1point3acres.com for more.

  44. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  45. 21. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴

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

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

  49. . 1point3acres.com/bbs

  50.             public int compare(Pair a, Pair b) {
  51. 23

  52.                 return a.val-b.val;
  53. 24.鐣欏璁哄潧-涓浜-涓夊垎鍦
  54. . 鍥磋鎴戜滑@1point 3 acres
  55.             }
  56. 25

  57.         });
  58. 26


  59. 27

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

  62.         int sum = 1;
  63. 29


  64. . from: 1point3acres.com/bbs
  65.         for (int i = 0; i < indexs.length; i++) {
  66. 30

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

  69.             sum += pairs[i].count;
  70. 32. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

  71.         }
  72. 33


  73. 34

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



  76.         for (int k = 1; k < Q; k++) {
  77. 36. more info on 1point3acres.com

  78.             int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));
  79. 37. 1point3acres.com/bbs
  80. . from: 1point3acres.com/bbs
  81.             if (index < 0) index = -index-1;
  82. 38

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

  85.         }
  86. 40

  87.         return res;
  88. 41

  89.     }
  90. 42
  91. -google 1point3acres

  92. 43



  93.     static class Pair{
  94. 44

  95.         public int val = 0;
  96. 45

  97.         public int count = 0;
  98. 46



  99.         public Pair(int val, int count) {
  100. 47

  101.             this.val = val;. Waral 鍗氬鏈夋洿澶氭枃绔,
  102. 48. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴

  103.             this.count = count;
  104. 49

  105.         }
  106. 50

  107.     }
  108. 51

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

使用道具 举报

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

使用道具 举报

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

想支持楼主,请点击帖子下方的"好苗""分享""收藏"键,酌情给楼主加大米(系统不扣你自己的分)。
积分不够看不了帖子,请参考论坛导航里的"帮助","新手提纲"里有攒积分指南
  1. 1
  2. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  3. import java.io.*;
  4. 2

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

  7. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
  8. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  9. 4



  10. public class Solution {
  11. 5
    . 鍥磋鎴戜滑@1point 3 acres



  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. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  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.         for (int i = 0; i < M; i++) {
  26. 12
  27. .鐣欏璁哄潧-涓浜-涓夊垎鍦
  28.             pairs[i] = new Pair(sc.nextInt(), sc.nextInt());
  29. 13
  30. . 1point 3acres 璁哄潧
  31.         }
  32. 14

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

  35.         for (int n: res) System.out.println(n);
  36. 16. 鍥磋鎴戜滑@1point 3 acres
  37. . 1point3acres.com/bbs
  38.     }
  39. 17

  40. .1point3acres缃
  41. 18

  42. .1point3acres缃
  43. .鏈枃鍘熷垱鑷1point3acres璁哄潧
  44.     public static int[] calculate(Pair[] pairs, int Q) {
  45. 19

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


  48. 21



  49.         Arrays.sort(pairs, new Comparator<Pair>(){
  50. 22. Waral 鍗氬鏈夋洿澶氭枃绔,



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

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

  55.             }
  56. 25

  57.         });
  58. 26

  59. . 鍥磋鎴戜滑@1point 3 acres
  60. 27

  61.         int[] indexs = new int[pairs.length];
  62. 28 鏉ユ簮涓浜.涓夊垎鍦拌鍧.

  63.         int sum = 1;
  64. 29
  65. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  66. . 1point 3acres 璁哄潧

  67.         for (int i = 0; i < indexs.length; i++) {
  68. 30
  69. . 鍥磋鎴戜滑@1point 3 acres
  70.             indexs[i] = sum;
  71. 31

  72.             sum += pairs[i].count;
  73. 32
  74. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  75.         }
  76. 33
  77. . 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴

  78. 34
  79. . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
  80.         int[] res = new int[Q-1];
  81. 35

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


  83.         for (int k = 1; k < Q; k++) {
  84. 36.鐣欏璁哄潧-涓浜-涓夊垎鍦

  85.             int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));
  86. 37
  87. . more info on 1point3acres.com
  88.             if (index < 0) index = -index-1;
  89. 38
  90. . 1point 3acres 璁哄潧
  91.             res[k-1] = pairs[index].val;
  92. 39

  93.         }
  94. 40

  95.         return res;
  96. 41. 1point 3acres 璁哄潧
  97. . visit 1point3acres.com for more.
  98.     }
  99. 42. visit 1point3acres.com for more.

  100. . From 1point 3acres bbs
  101. 43.鐣欏璁哄潧-涓浜-涓夊垎鍦

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

  103.     static class Pair{
  104. 44

  105.         public int val = 0;
  106. 45

  107.         public int count = 0;
  108. 46. more info on 1point3acres.com
  109. -google 1point3acres


  110.         public Pair(int val, int count) {
  111. 47. 鍥磋鎴戜滑@1point 3 acres

  112.             this.val = val;
  113. 48

  114.             this.count = count; 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
  115. 49

  116.         }
  117. 50

  118.     }
  119. 51.1point3acres缃

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

使用道具 举报

本版积分规则

关闭

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

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

custom counter

GMT+8, 2017-5-27 22:00

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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