由买买提看人间百态

topics

全部话题 - 话题: arg
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)
j*******h
发帖数: 20
1
来自主题: JobHunting版 - find the first missing positive integer.
public class FirstMissingPositive {
int min;//Integer.MAX_VALUE;
int max;//Integer.MIN_VALUE;

private void checkMinMax(){
if( max > 0 && min > 0 ){
if( max < min ){
int temp = min;
min = max;
max = temp;
}
if( max - min > 1 )
max = -1;
}
}

public int firstMissingPositive(int[] A) {
// Start typing your Java... 阅读全帖
Z*****Z
发帖数: 723
2
来自主题: JobHunting版 - 这道硬币找零题有好的DP解法么?
把所有硬币放在一个数组c里面。然后函数F[i,j]代表用前i个硬币摆出value j的摆法。
初始F[*,*] = 0
然后F[i,j] = sum(F[i-1, j - k * c[i]]) 0 <= k <= j/c[i]
实现起来可以用背包九讲里面第二讲的方法:
F[i,j] = F[i, j - c[i]] + F[i-1, j]
代码:
package common.knapsack;
public class Complete {
public static void main(String[] args) {
int[] in = {1, 5, 10, 25};
System.out.println(howMany(in, 11));
}
//How many ways to pack

public static int howMany(int[] arr, int n){
... 阅读全帖
p*****2
发帖数: 21240
3
来自主题: JobHunting版 - 这道硬币找零题有好的DP解法么?
写了一个topdown dp的。
import java.io.*;
import java.util.*;
public class Coin
{
public static void main(String[] args)
{
new Coin().run();
}
PrintWriter out = null;
int[][] dp = null;
void run()
{
Scanner in = new Scanner(System.in);
out = new PrintWriter(System.out);
int[] arr = new int[]
{ 25, 10, 5, 1 };
int n = 11;
dp = new int[arr.length][n + 1];
for (int i = 0; i < arr.length; i++)
Arrays.fil... 阅读全帖
t**********h
发帖数: 2273
4
来自主题: JobHunting版 - 发一个有趣的java题
今天面了一个和下面类似的一个题,很有意思,大家一起看看。写出打印的东西
class Egg2 {
protected class Yolk {
public Yolk() { print("Egg2.Yolk()"); }
public void f() { print("Egg2.Yolk.f()");}
}
private Yolk y = new Yolk();
public Egg2() { print("New Egg2()"); }
public void insertYolk(Yolk yy) { y = yy; }
public void g() { y.f(); }
}
public class BigEgg2 extends Egg2 {
public class Yolk extends Egg2.Yolk {
public Yolk() { print("BigEgg2.Yolk()"); }
public void f() { print("BigEgg2.Yolk.f()"); }
}
p... 阅读全帖
Z*****Z
发帖数: 723
5
来自主题: JobHunting版 - 问道leetcode上的题
最直白的算法不行么?
public class Stock{
public static void main(String[] args){
int[] arr = {6,1,3,2,4,7};
System.out.println(stock(arr));
}
static int stock(int[] 股票){
assert(股票 != null && 股票.length > 0);
int 我的钱 = 0;
int 低点 = 股票[0];
for(int i = 0; i < 股票.length; i ++){
if(股票[i] <= 低点){
低点 = 股票[i];
} else if(i == 股票.length - 1 || i < 股票.lengt... 阅读全帖
Z*****Z
发帖数: 723
6
来自主题: JobHunting版 - 真心问一道题
二爷,看不太懂 :(
写了两个testcase您看看?
public class SearchSequence {
static String min(String str, String word) {
int n = str.length();
int m = word.length();
int[][] dp = new int[n + 1][m + 1];
for (int i = 0; i <= n; i++)
dp[i][m] = 0;
for (int j = 0; j < m; j++)
dp[n][j] = n + 1;
for (int i = n - 1; i >= 0; i--)
for (int j = m - 1... 阅读全帖
d**e
发帖数: 6098
7
我觉得跟recursive没关系,区别应该是一样的。
但我觉得下面的例子不太好。arg+1应该是一个新的临时变量了。
c********r
发帖数: 286
8
来自主题: JobHunting版 - 问一道题
public class FindDuplicatedInt {
public static int FindDup(int[] arr)
{
if(arr.length > 1002 || arr == null) return -1;
int checker = 0;
for(int i = 0;i int val = arr[i];
if((checker & (1<0){
return val;
}
checker |= (1< }
return -1;
}
public static void main(String[] args) {
int [] a = new int[]{1,2,3,4,5,6,7,8,9,10,2};
System.out.pri... 阅读全帖
c********r
发帖数: 286
9
来自主题: JobHunting版 - 问一道题
这个应该没问题了,欢迎大家指正
public static int FindDup2(int[] arr)
{
if(arr.length > 1002 || arr == null) return -1;
boolean[] check = new boolean[1002];
for(int i =0;i if(check[arr[i]])
{
return arr[i];
}else{
check[arr[i]]=true;
}
}

return -1;
}
public static void main(String[] args) {
int [] a = new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13,... 阅读全帖
Z*****Z
发帖数: 723
10
来自主题: JobHunting版 - 问道string match的题
public static void main(String[] args) {
System.out.println(getCommon("1234", "3451"));
System.out.println(getCommon("12", "123"));
System.out.println(getCommon("123", "12"));
System.out.println(getCommon("12", "12"));
}
static String getCommon(String s1, String s2) {
char[] arr1 = s1.toCharArray();
char[] arr2 = s2.toCharArray();
int[] failure = buildFailureTable(arr2);
int i = -1, j = -1;

if(arr2.length < arr1.leng... 阅读全帖
r****m
发帖数: 70
11
来自主题: JobHunting版 - 贡献T家新鲜面经,求个bless
package test;
public class MapTest implements Runnable{

int[] a;
int index = 0;

MapTest(int[] a) {
this.a = a;
}

int fun(int i) {
return i+1;
}

@Override
public void run() {
int i;
while((i = getIndex()) < a.length) {
System.out.println(Thread.currentThread().getName() + " " + i);
a[i] = fun(a[i]);
}
}

synchronized int getIndex() {
return (index++);
}
static... 阅读全帖
Z*****Z
发帖数: 723
12
来自主题: JobHunting版 - 一道题目
上代码。
static int findCommon(int[][] intArrs){

if(intArrs == null || intArrs.length == 0){
return -1;
}

for(int[] arr : intArrs){
if(arr == null || arr.length == 0){
return -1;
}
}

int[] pointers = new int[intArrs.length];

int ans = intArrs[0][0];

boolean found = false;
while(!found){

found = ... 阅读全帖
r****t
发帖数: 10904
13
来自主题: JobHunting版 - 准备不好面试就是会悲剧
map args是搞反了吧?
r****t
发帖数: 10904
14
来自主题: JobHunting版 - 准备不好面试就是会悲剧
map args是搞反了吧?
Z*****Z
发帖数: 723
15
来自主题: JobHunting版 - 问G家一道电面题
写个练手
public static void main(String[] args) {
System.out.println(countOccurrence("gcagagagcagagag", "gcagagag"));
}
public static int countOccurrence(String haystack, String needle){

char[] str = haystack.toCharArray();
char[] pattern = (needle + '\0').toCharArray();
int n = needle.length();

int[] table = buildFailureTable(pattern);

int count = 0;
int i = 0, j = 0;
while(i < str.length){
while... 阅读全帖
f*****n
发帖数: 15
16
one way to solve it is to use DP. runtime is O(n^2) and it requires O(n)
extra space.
import java.util.ArrayList;
import java.util.List;
public class StringOperation {
public static void main(String[] args) {
StringOperation strOp = new StringOperation();
System.out.println(strOp.findLongRepeatedString("banana"));
System.out.println(strOp.findLongRepeatedString("aaaaa"));
}

public String findLongRepeatedString(String src) {
Result longestResult = n... 阅读全帖
s******c
发帖数: 99
17
来自主题: JobHunting版 - 问一道interview street 上的题
import java.io.*;
public class Solution {
public static void main(String args[] ) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.
in));
String line = br.readLine();
int N = Integer.parseInt(line);
String []strs=new String[N];
for (int i = 0; i < N; i++) {
strs[i]=br.readLine();
}

for(int i=0;i {
char start=strs[i].charAt(0);
int sumtotal=0... 阅读全帖
z******e
发帖数: 82
18
来自主题: JobHunting版 - G电面一题
public class Test {
public static void main(String[] args) {
test("12023456", "", 0);
}
public static void test(String nums, String out, int start) {
if (nums == null || start == nums.length()) {
System.out.println(out);
return;
}
int i = nums.charAt(start) - '0';
if (i != 0) {
test(nums, out + (char) (i + 64), start + 1);
if (start + 1 < nums.length()) {
i = Integer.parseInt(nums.... 阅读全帖
k*******t
发帖数: 202
19
来自主题: JobHunting版 - 问个java List的问题
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Foo {
String name;
int number;

List friends;
public boolean equals(Object obj)
{
System.out.println(friends);
System.out.println(test.friends);
System.out.println(test.name);
System.out.println(this.name);

return number == test.number
&& (name == test.name
|| (name != null && name.equals(... 阅读全帖
h**********9
发帖数: 3252
20
来自主题: JobHunting版 - 请问G一题

客气点好吗?我又不是全职解题的,拖家带口的有点时间不容易.
还有一些地方没想通,就当这个是 heuristic greedy 解,不一定能算出最优解,先给
个 O((Max(x) - Min(x))*N^2) 的 code, 谁能帮忙验证一下? 如果可行我再解析O((
Max(x) - Min(x))*N*LG(N))。
import java.util.Arrays;
public class Partition {

public static int getMinDifference(int input[]) {
assert (input.length % 2 == 0) : "Input must have even number of
items.";
Arrays.sort(input);
int x[] = new int[input.length / 2];
int y[] = new int[input.length / 2];
for(int i = 0; i < x.... 阅读全帖
h**********9
发帖数: 3252
21
来自主题: JobHunting版 - 请问G一题

客气点好吗?我又不是全职解题的,拖家带口的有点时间不容易.
还有一些地方没想通,就当这个是 heuristic greedy 解,不一定能算出最优解,先给
个 O((Max(x) - Min(x))*N^2) 的 code, 谁能帮忙验证一下? 如果可行我再解析O((
Max(x) - Min(x))*N*LG(N))。
import java.util.Arrays;
public class Partition {

public static int getMinDifference(int input[]) {
assert (input.length % 2 == 0) : "Input must have even number of
items.";
Arrays.sort(input);
int x[] = new int[input.length / 2];
int y[] = new int[input.length / 2];
for(int i = 0; i < x.... 阅读全帖
h**********9
发帖数: 3252
22
来自主题: JobHunting版 - 弱问一道G题
public class Divisible {
public static void main(String args[]) {
int a1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int a2[] = { 1, 2, 3, 4, 7, 10 };
System.out.println(isDivisible(a1, 5));
System.out.println(isDivisible(a2, 3));
}

public static boolean isDivisible(int a[], int k) {
assert (a != null && a.length % 2 == 0);
assert (k != 0);

int count[] = new int[k];
for(int i = 0; i < a.length; i++) {
... 阅读全帖
m*****k
发帖数: 731
23
来自主题: JobHunting版 - 一道java面试题
在下面这个程序中,如果sort后的totalTime 总是比不sort的totalTime 小,
你可否解释是啥原因?
public class Work {
public static void main(String args[]) {

int a[] = new int[1000000000];

//fill a

//sort a
//do not sort a

starttime=System.currentTimeMillis()
for (int i=0;i process(a[i]);
}
endtime=System.currentTimeMillis()

totalTime = endtime-starttime;
}


process(int element) ... 阅读全帖
Q*******e
发帖数: 939
24
来自主题: JobHunting版 - 一道C语言题
What's the compiler??
aa.c: In function `main':
aa.c:12: warning: passing arg 1 of `foo' from incompatible pointer type
on small endian:
# ./a.out
1
on big endian machine:
# ./a.out
0
s********x
发帖数: 914
25
来自主题: JobHunting版 - 新鲜G面筋(2)
切磋一下. running time 应该是 less than log(K)
public class RandomNextIntExceptK {
private int[] kk;
private int[] kAdd;
private Random rand = new Random();
public RandomNextIntExceptK(int[] k) {
Map kCount = new TreeMap();
for (int i = 0; i < k.length; i++)
{
int key = k[i] - i;
if (kCount.containsKey(key))
{
int count = kCount.get(key);
kCount.put(key, cou... 阅读全帖
e****e
发帖数: 418
26
来自主题: JobHunting版 - A电面
Just my 2 cents.
public class Cloth {
int size;
int quantity;
String brand;
String name;
BigDecimal price;
}
public class ClothService {

// lookup cloth table in database to see if quality is 0;
public boolean query(Cloth c) {
//...
}

public void addCloth(Cloth c) {
//...
}

public void soldCloth(Cloth c) {
//...
}
}
public class Client {
public static void main(String[] args) {
Cloth c = new Cloth();
... 阅读全帖
i********m
发帖数: 332
27
来自主题: JobHunting版 - 这个BST题目为何错了?
For every object that is not a primitive type, it's passed by reference.
Only the primitive type and their wrapper are passed by value.
for example :
public void foo (Integer i) {
i = 9;
}
public static void main (String[] args) {
Integer i = new Integer (10);
foo(i);
System.out.println(i);
//The value is still 10 in i, not 9
}
w***o
发帖数: 109
28
来自主题: JobHunting版 - 两道google的题
第一题,O(n) with O(1) space:
public static void main(String[] args) {
int[] test = {-2,-101,-100,-102,-1};

int[] ret = new int[3];
int count = 1;
int min = 0;
for(int i = 1; i < test.length; i++) {
int x = test[i];
if(x > test[ret[count - 1]]) {
ret[count++] = i;
if(count == 3) break;
} else {
if(x <= test[min])
min = i;
... 阅读全帖
r**d
发帖数: 90
29
来自主题: JobHunting版 - 贡献一道题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static private bool isWord(string s)
{
switch (s)
{
case "this":
case "is":
case "a":
case "all":
case "some":
case "allsome":
return true;
}
return fal... 阅读全帖
R**y
发帖数: 72
30
来自主题: JobHunting版 - Algorithm 4th Edition
使用过。。。 如果配置main(string[] args)这样的参数进去是知道的
但是有个别命令像 java Insertion < input.txt
这样的命令就不知道怎么配置进run configuration了
z******w
发帖数: 36
31
来自主题: JobHunting版 - 这道题DP怎么做阿
//用dp做的一个O(n^3)的解
import java.util.Scanner;
public class StreetTraversal {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][] dis = new int[n][n];
for (int i = 0; i < n; i ++) {
dis[i] = new int[n];
for (int j = 0; j < n; j ++) {
dis[i][j] = sc.nextInt();
}
}
int[][] dp = new int[n+1][n+1];
for (int i = 1; i <= n; i ++)
... 阅读全帖
c*****a
发帖数: 808
32
来自主题: JobHunting版 - ooyala电面
練一下
//print matrix in diagnal
public static void printMat(int[][]mat){
for(int i =0;i int temp = i, j =0;
while( i>=0 && j System.out.print(mat[j++][i--] +" ");
i=temp;
System.out.println();
}
for(int i =1;i int temp = i, j=mat[0].length-1;
while(i=0)
System.out.print(mat[i++][j--] +" "... 阅读全帖
s*********5
发帖数: 53
33
1, 程序附在后面, 里面的p q r 是随机生成的。
2, 没有,但这个题是当前决策啊,n-3影响n-2
3, 你说的情况应该要算期望,但这个题的意思不就是想要到一个最大的结果么。
例如我们俩之骰子,我已经扔了个5
你有3次机会A,B,C可以掷,
只要max(A,B,C) = 6就赢$100,
max(A,B,C) = 5 我们平手
max(A,B,C) < 5 你输给我$100 , 我想你一定会干的,而且你希望和我玩的次数越多越
好,对吧?
那么你如果只有两次机会了,你还会干嘛?其实不会了,因为你输的可能大。但我如果
说我们平手你照样拿$100, 那么你又会同意一直玩下去。
我就是这么理解的,code 如下:
public class Dice{
public static void main(String[] args){
final int N = 1000000;
int win = 0;
int lose = 0;
int equal = 0;

for... 阅读全帖
s****0
发帖数: 117
34
我觉得你没有理解人家的思路。这里是我的Java实现,仅供参考。
//- 5.2.3 Generation with minimal changes
package mylib;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Perm implements Iterable>, Iterator> {
final int n;
final int pos[];
final Integer perm[];
final boolean dir[];
final T[] data;
int cnt;
public Perm(List data) {
this.n = data.size();
pos = new int[n];
perm = new Integer[n];
dir = new boo... 阅读全帖
p*****2
发帖数: 21240
35
来自主题: JobHunting版 - 对scala很失望

我工作不用呀。刚才看了一下,是某个test case超时了,所以不是编译的问题。计时
是计的那个test case。大牛帮我看看这个程序哪里可以提高一些?跟java的算法完全
一样。慢了那么多。
object test {
def main(args: Array[String]): Unit = {
val s=readLine
val a=new Array[Int](s.length())
var i=0
var j=s.length-1
for(k <- 0 to s.length-1)
if(s(k)=='l')
{
a(j)=k+1
j-=1
}
else
{
a(i)=k+1
i+=1
}
a.foreach(println)
}
}
void run() throws Exception
{
... 阅读全帖
f*******t
发帖数: 7549
36
来自主题: JobHunting版 - 问一道题
Java版本比较方便,可以用ArrayList自带的iterator。C++如果只需要实现类似于Java
iterator的两个接口,倒是不难。
public class DoubleLevelArrayListIterator {
private Iterator> itLvl1;
private Iterator itLvl2;

public DoubleLevelArrayListIterator(ArrayList> a) {
itLvl1 = a.iterator();
itLvl2 = null;
}

public boolean hasNext() {
if (itLvl2 != null && itLvl2.hasNext()) {
return true;
} else {
while ((itLvl2 == ... 阅读全帖
s****0
发帖数: 117
37
来自主题: JobHunting版 - 一道A家店面题求解
大概是这个意思. 我没理解最后两种情况怎么处理,好像结果不确定。
package myutil;
import java.util.Arrays;
public class FlexSearch {
final Integer[] data;
final boolean asc;
public FlexSearch(Integer[] data) {
if (data == null || data.length < 2)
throw new java.lang.NoSuchFieldError();// whatever.
this.data = data;
asc = data[0] - data[1] < 0;
}
private int getIdx(int val) {
return Arrays.binarySearch(data, val);
}
public int getLTMax(int val) {
int... 阅读全帖
w********p
发帖数: 948
38
来自主题: JobHunting版 - 最失败的一次onsite - bloomberg
evaluator (String expression)
1。将expression parse 成三块 expr1 operator expr2
2 。如果expr1, expr2 都是数字,return 计算结果。 比如6*6
3。 不然,如果operator 是乘除的话,parse 来string2里的第一个数字,得到结果
4. 再不然,recursively call for rest expression.
有两个links很好和大家分析。
http://www.strchr.com/expression_evaluator
http://compsci.ca/v3/viewtopic.php?t=21703
把网上的code帖出来,给爱偷懒的同伙。我还没仔细看。
无意中运行了下面的code,并不能handle所有的cases 。个人还是喜欢stack的版本。
不会没关系,学学就会了吗。呵呵, 会了不用还是会忘嘛。
本科compiler课是要用java写一个compiler出来的。还有微积分,还给老师的知识还少
嘛?。。。
/*
* The "ExpressionEv... 阅读全帖
s****0
发帖数: 117
39
package myutil;
import java.util.Scanner;
import java.util.Stack;
public class ParseExp {
Stack oprand = new Stack();
Stack oprator = new Stack();
static int[] code = new int[256];
static {
code['+'] = 10;
code['-'] = 11;
code['*'] = 20;
code['/'] = 21;
code['^'] = 30;
code['$'] = 0;
code['('] = 100;
code[')'] = 1;
}
public ParseExp() {
}
public Integer parse(String... 阅读全帖
s****0
发帖数: 117
40
package myutil;
import java.util.Scanner;
import java.util.Stack;
public class ParseExp {
Stack oprand = new Stack();
Stack oprator = new Stack();
static int[] code = new int[256];
static {
code['+'] = 10;
code['-'] = 11;
code['*'] = 20;
code['/'] = 21;
code['^'] = 30;
code['$'] = 0;
code['('] = 100;
code[')'] = 1;
}
public ParseExp() {
}
public Integer parse(String... 阅读全帖
f*******t
发帖数: 7549
41
来自主题: JobHunting版 - 问两道面试中碰到的题目
看不懂前面第二题的解法,自己写了个O(n^3)的
public class MinPalindromeSplits {

private int[][] dp;

private boolean isPalindrome(String s) {
if (s.length() < 2)
return true;
for (int i = 0; i <= s.length() / 2; i++) {
if (s.charAt(i) != s.charAt(s.length() - i - 1))
return false;
}
return true;
}

public int minSplits(String s) {
dp = new int[s.length() + 1][s.length() + 1];

for (int len = 1; l... 阅读全帖
l**h
发帖数: 893
42
来自主题: JobHunting版 - LinkedIn 面经
实现两个函数: H() and O(), 这两个函数会被多线程调用。当一个线程调用H或O时
,如果当前已经有至少两个线程call H和一个线程call O。那么让两个call H和一个
call O的线程返回(产生一个水分子),其他的都block。
写了个Java版本的,大家指教:
import java.util.*;
import java.util.concurrent.*;
public class ThreadH2OSema {
private final Semaphore hCalled = new Semaphore(0);
private final Semaphore hUsed = new Semaphore(0);
private final Semaphore oCalled = new Semaphore(0);
private final Semaphore oUsed = new Semaphore(0);
public void H() {
try {
h... 阅读全帖
l**h
发帖数: 893
43
来自主题: JobHunting版 - LinkedIn 面经
实现两个函数: H() and O(), 这两个函数会被多线程调用。当一个线程调用H或O时
,如果当前已经有至少两个线程call H和一个线程call O。那么让两个call H和一个
call O的线程返回(产生一个水分子),其他的都block。
写了个Java版本的,大家指教:
import java.util.*;
import java.util.concurrent.*;
public class ThreadH2OSema {
private final Semaphore hCalled = new Semaphore(0);
private final Semaphore hUsed = new Semaphore(0);
private final Semaphore oCalled = new Semaphore(0);
private final Semaphore oUsed = new Semaphore(0);
public void H() {
try {
h... 阅读全帖
h**u
发帖数: 144
44
来自主题: JobHunting版 - LinkedIn 面经
用了两个blocking queue, 还请大侠指教!
import java.util.concurrent.LinkedBlockingQueue;
public class H2O {
LinkedBlockingQueue hQueue = new LinkedBlockingQueue();
LinkedBlockingQueue oQueue = new LinkedBlockingQueue();
Object o = new Object();
public void h() throws InterruptedException {
hQueue.put(Thread.currentThread());
synchronized (o){
System.out.println(Thread.currentThread().getName() + ".h,
notify");
o.notify()... 阅读全帖
h**u
发帖数: 144
45
来自主题: JobHunting版 - LinkedIn 面经
用了两个blocking queue, 还请大侠指教!
import java.util.concurrent.LinkedBlockingQueue;
public class H2O {
LinkedBlockingQueue hQueue = new LinkedBlockingQueue();
LinkedBlockingQueue oQueue = new LinkedBlockingQueue();
Object o = new Object();
public void h() throws InterruptedException {
hQueue.put(Thread.currentThread());
synchronized (o){
System.out.println(Thread.currentThread().getName() + ".h,
notify");
o.notify()... 阅读全帖
p*****2
发帖数: 21240
46
来自主题: JobHunting版 - 准备转回Java了

object test6 extends App {
val sc=new Scanner(System.in)
val n=sc.nextInt
val m=sc.nextInt
val mat=new Array[String](n)
val start=System.currentTimeMillis()
for(i<-0 until n) mat(i)=sc.next()

def check(i:Int, j:Int, k:Int, l:Int):Boolean={
val minX=math.min(i,k)
val maxX=math.max(i,k)
val minY=math.min(j,l)
val maxY=math.max(j,l)

var minR=true
var maxR=true
var minC=true
var maxC=true
... 阅读全帖
f*******t
发帖数: 7549
47
来自主题: JobHunting版 - 刚面的,发一个google新题
写了一下,牛算法实现和理解起来挺简单的
import java.util.PriorityQueue;
public class RainWater2D {
private final int[][] directions = {
{1, 0}, {0, 1}, {-1, 0}, {0, -1}
};

private int width, height;

private class Point implements Comparable {
public int x, y, h;
public Point(int y, int x, int h) {
this.y = y;
this.x = x;
this.h = h;
}
@Override
public int compareTo(Point p) {
return h >... 阅读全帖
p*****2
发帖数: 21240
48
来自主题: JobHunting版 - 有人做hackranker的题么
刚做了一题,感觉不错。准备好好做做了。哈哈。我这个代码过了第一题
object Solution {
def main(args: Array[String]) {
val n=readLine.toInt
val arr=readLine.split(" ").map(_.toInt)
val last=arr.last
var i=arr.length-2
while(i>=0 && arr(i)>last) {arr(i+1)=arr(i); println(arr.mkString("
"));i-=1}
arr(i+1)=last
println(arr.mkString(" "))

}
}
w***o
发帖数: 109
49
来自主题: JobHunting版 - 有人做hackranker的题么
用这个Template就可以了:
import java.util.*;
class Solution{
static public void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
m = in.nextInt();
k = in.nextInt();
// your code
System.out.println(ret);
}
}
z***2
发帖数: 66
50
来自主题: JobHunting版 - 问个题,火车运煤的DP解法
佩服!
import java.util.*;
class train {
public static void main(String[] args) {
double table[]=new double [10001];

table[0]=3000.0;

for(int i =1; i double localMax=-1.0;
double curDistance= i/10+ (double)(i%10)*1/10;
//System.out.println(curDistance);
for(int j=0; j
double totalLeft = table[j];
double prevDistance= j/10+ (double)(... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)